全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:988
推到 Plurk!
推到 Facebook!

關於ComboBox的問題

答題得分者是:Fishman
oxpretaa
一般會員


發表:3
回覆:2
積分:1
註冊:2004-05-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-30 15:06:58 IP:203.72.xxx.xxx 未訂閱
想請教各位前輩們,問題在程式中間!! unit MailLogin_u; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls, Buttons, AccountListForm_u; type TMailServiceInfo = record Domain:string; URL:string; PageTitle:string; FormName,IDFieldName,PasswordFieldName:OleVariant; ID:string; Password:string; end; type TForm1 = class(TForm) wb: TWebBrowser; account: TComboBox; CtrlPanel: TPanel; Label1: TLabel; login_btn: TSpeedButton; exit_btn: TSpeedButton; accountlist_btn: TSpeedButton; siteinfo: TMemo; mark: TLabel; procedure wbDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); procedure FormResize(Sender: TObject); procedure login_btnClick(Sender: TObject); procedure accountChange(Sender: TObject); procedure exit_btnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure accountlist_btnClick(Sender: TObject); procedure FormActivate(Sender: TObject); procedure markClick(Sender: TObject); procedure markMouseEnter(Sender: TObject); procedure markMouseLeave(Sender: TObject); private FAccountFilename:TFileName; FMail:TMailServiceInfo; FPasswordList:TStrings; procedure ReadAccounts; procedure SaveAccounts; procedure SetMailInfo; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} type GetDirection = (getBefore, getAfter); function GetSubstring(AStr:string; Direction:GetDirection; Delim:char):string; var i:integer; begin i:=Pos(Delim,AStr); if i>0 then case Direction of getBefore:Result:=Copy(AStr,1,i-1); getAfter:Result:=Copy(AStr,i 1,Length(AStr)-i); end else Result:=''; end; procedure TForm1.ReadAccounts; var i:integer; begin if FileExists(FAccountFilename) then begin FPasswordList.LoadFromFile(FAccountFilename); account.Clear; for i:=0 to FPasswordList.Count-1 do begin account.Items.Add(GetSubstring(FPasswordList[i],getBefore,':')); FPasswordList[i]:=GetSubstring(FPasswordList[i],getAfter,':'); end; end; account.Text:='Choose your account...'; ^^^^^^^^^^^^^^^^^^^^ 預設是這個字串,可是我現在想要把這個預設的地方 改成我所輸入的第一位使用者,就是資料裡頭的第一筆資料 (帳號及密碼),但是怎麼試都試不出來 end; //它的TcomboBox的Name是account procedure TForm1.SaveAccounts; var ss:TStrings; i:integer; begin ss:=TStringList.Create; ss.Clear; try for i:=0 to account.Items.Count-1 do ss.Add(account.Items[i] ':' FPasswordList[i]); ss.SaveToFile(FAccountFilename); finally ss.Free; end; end; procedure TForm1.SetMailInfo; var s,FormParam:string; begin FMail.ID:=GetSubstring(account.Text,getBefore,'@'); FMail.Domain:=LowerCase(GetSubstring(account.Text,getAfter,'@')); if FMail.Domain='hotmail.com' then FMail.ID:=FMail.ID '@hotmail.com'; s:=siteinfo.Lines.Values[FMail.Domain]; FMail.URL:=GetSubstring(s,getBefore,'|'); s:=GetSubstring(s,getAfter,'|'); FMail.PageTitle:=GetSubstring(s,getBefore,'|'); s:=GetSubstring(s,getAfter,'|'); FormParam:=GetSubstring(s,getBefore,'|'); s:=GetSubstring(s,getAfter,'|'); FMail.IDFieldName:=GetSubstring(s,getBefore,'|'); FMail.PasswordFieldName:=GetSubstring(s,getAfter,'|'); //處理FormName的狀況:字串或Index值 if FormParam[1]='#' then FMail.FormName:=StrToInt(Copy(FormParam,2,Length(FormParam)-1)) else FMail.FormName:=FormParam; FMail.Password:=FPasswordList[account.ItemIndex]; end; procedure TForm1.wbDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var doc,wform:OleVariant; begin doc:=wb.OleObject.Document; if Pos(FMail.PageTitle,doc.title)>0 then begin wform:=doc.Forms.Item(FMail.FormName); wform.Item(FMail.IDFieldName,0).value:=FMail.ID; wform.Item(FMail.PasswordFieldName,0).value:=FMail.Password; wform.submit; FMail.PageTitle:=''; end; end; procedure TForm1.FormResize(Sender: TObject); begin wb.Top:=CtrlPanel.Height; wb.Left:=0; wb.Width:=Width-8; wb.Height:=Height-CtrlPanel.Height-32; exit_btn.Left:=wb.Left wb.Width-exit_btn.Width; accountlist_btn.Left:=exit_btn.Left-accountlist_btn.Width-4; mark.Left:=accountlist_btn.Left-mark.Width-12; end; procedure TForm1.login_btnClick(Sender: TObject); begin self.SetMailInfo; wb.Navigate(FMail.URL); end; procedure TForm1.accountChange(Sender: TObject); begin if account.ItemIndex>=0 then login_btn.Enabled:=true; end; procedure TForm1.exit_btnClick(Sender: TObject); begin close; end; procedure TForm1.FormCreate(Sender: TObject); begin FPasswordList:=TStringList.Create; FAccountFilename:=ChangeFileExt(Application.ExeName,'.INI'); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin FPasswordList.Free; end; procedure TForm1.accountlist_btnClick(Sender: TObject); var i:integer; begin AccountListForm:=TAccountListForm.Create(self); for i:=0 to account.Items.Count-1 do AccountListForm.accs.Strings.Add(account.Items[i] '=' FPasswordList[i]); for i:=1 to siteinfo.Lines.Count-1 do AccountListForm.domain.Items.Add('@' siteinfo.Lines.Names[i]); try if AccountListForm.ShowModal=mrOK then begin account.Clear; FPasswordList.Clear; for i:=0 to AccountListForm.accs.Strings.Count-1 do begin account.Items.Add(AccountListForm.accs.Strings.Names[i]); FPasswordList.Add(AccountListForm.accs.Strings.Values[account.Items[i]]); end; SaveAccounts; end; finally AccountListForm.Free; end; end; procedure TForm1.FormActivate(Sender: TObject); begin if FileExists(FAccountFilename) then ReadAccounts else begin ShowMessage(#13 ' 您還沒有指定帳號… ' #13); accountlist_btn.Click; end; end; procedure TForm1.markClick(Sender: TObject); begin FMail.PageTitle:=''; wb.Navigate('http://delphi.ktop.com.tw'); end; procedure TForm1.markMouseEnter(Sender: TObject); begin mark.Font.Color:=clBlue; end; procedure TForm1.markMouseLeave(Sender: TObject); begin mark.Font.Color:=clGreen; end; end.
Fishman
尊榮會員


發表:120
回覆:1949
積分:2163
註冊:2006-10-28

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-30 15:39:18 IP:210.65.xxx.xxx 未訂閱
Hi oxpretaa,    試試 account.Text:='Choose your account...'; 更改為 account.ItemIndex := 0;     ---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman
oxpretaa
一般會員


發表:3
回覆:2
積分:1
註冊:2004-05-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-30 15:51:31 IP:203.72.xxx.xxx 未訂閱
太謝謝你了…已經可以用了…>"<感動
系統時間:2024-11-22 9:06:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!