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

關於function的問題想請教

尚未結案
LearnDelphi
一般會員


發表:4
回覆:7
積分:2
註冊:2005-04-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-07 20:58:06 IP:59.120.xxx.xxx 未訂閱
程式1 一開始寫簡單資料上下筆查詢的程式 後來想要加入function的函數 程式2 加了function宣告... 但是不能執行..請問大家..我哪裡做錯或是忽略了呢 程式1. ********************* unit CUS01U1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, StdCtrls, Mask, DBCtrls, ExtCtrls; type TForm1 = class(TForm) PanFunction: TPanel; First: TButton; Prioor: TButton; Next: TButton; Last: TButton; PanMeat: TPanel; EditCusNo: TDBEdit; DataSource1: TDataSource; LabCompany: TLabel; EditCompany: TDBEdit; LabAddr1: TLabel; EditAddr1: TDBEdit; LabAddr2: TLabel; EditAddr2: TDBEdit; LabCity: TLabel; EditCity: TDBEdit; LabState: TLabel; EditState: TDBEdit; LabZip: TLabel; EditZip: TDBEdit; Labcountry: TLabel; EditCountry: TDBEdit; LabPhone: TLabel; EditPhone: TDBEdit; LabFax: TLabel; EditFax: TDBEdit; LabTaxRate: TLabel; EditTaxRate: TDBEdit; LabContact: TLabel; EditContact: TDBEdit; LabLastDate: TLabel; EditLastlDate: TDBEdit; LabCusNo: TLabel; procedure FirstClick(Sender: TObject); procedure PrioorClick(Sender: TObject); procedure NextClick(Sender: TObject); procedure LastClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses CUS01U2; var CusNo : String; {$R *.DFM} procedure TForm1.FirstClick(Sender: TObject); begin CusDaMd.QueryCus.Close; CusDaMd.QueryCus.SQL.Clear; CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo = (select min(CustNo)from customer)'); CusDaMd.QueryCus.Open; CusNo := CusDaMd.QueryCus.FieldByName('CustNo').AsString; end; procedure TForm1.PrioorClick(Sender: TObject); begin CusDaMd.QueryCus.Close; CusDaMd.QueryCus.SQL.Clear; CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo =(select max(CustNo)from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo <''' CusNo ''')'); CusDaMd.QueryCus.Open; CusNo := CusDaMd.QueryCus.FieldByName('CustNo').AsString; end; procedure TForm1.NextClick(Sender: TObject); begin CusDaMd.QueryCus.Close; CusDaMd.QueryCus.SQL.Clear; CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo =(select min(CustNo)from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo >''' CusNo ''')'); CusDaMd.QueryCus.Open; CusNo := CusDaMd.QueryCus.FieldByName('CustNo').AsString; end; procedure TForm1.LastClick(Sender: TObject); begin CusDaMd.QueryCus.Close; CusDaMd.QueryCus.SQL.Clear; CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo = (select max(CustNo)from customer)'); CusDaMd.QueryCus.Open; CusNo := CusDaMd.QueryCus.FieldByName('CustNo').AsString; end; end.
LearnDelphi
一般會員


發表:4
回覆:7
積分:2
註冊:2005-04-07

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-07 21:02:28 IP:59.120.xxx.xxx 未訂閱
程式2.(加function) *********************** unit CUS01U1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, StdCtrls, Mask, DBCtrls, ExtCtrls; type TForm1 = class(TForm) PanFunction: TPanel; First: TButton; Prioor: TButton; Next: TButton; Last: TButton; PanMeat: TPanel; EditCusNo: TDBEdit; DataSource1: TDataSource; LabCompany: TLabel; EditCompany: TDBEdit; LabAddr1: TLabel; EditAddr1: TDBEdit; LabAddr2: TLabel; EditAddr2: TDBEdit; LabCity: TLabel; EditCity: TDBEdit; LabState: TLabel; EditState: TDBEdit; LabZip: TLabel; EditZip: TDBEdit; Labcountry: TLabel; EditCountry: TDBEdit; LabPhone: TLabel; EditPhone: TDBEdit; LabFax: TLabel; EditFax: TDBEdit; LabTaxRate: TLabel; EditTaxRate: TDBEdit; LabContact: TLabel; EditContact: TDBEdit; LabLastDate: TLabel; EditLastlDate: TDBEdit; LabCusNo: TLabel; procedure FirstClick(Sender: TObject); procedure PrioorClick(Sender: TObject); procedure NextClick(Sender: TObject); procedure LastClick(Sender: TObject); function ToRecord(QueryDateSet : TQuery ; ActRecord : string ): Boolean; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses CUS01U2; var CusNo : String; {$R *.DFM} procedure TForm1.FirstClick(Sender: TObject); begin ToRecord (CusDaMa.QueryCus,'FirstRun'); end; procedure TForm1.PrioorClick(Sender: TObject); begin ToRecord (CusDaMa.QueryCus,'PriorRun'); end; procedure TForm1.NextClick(Sender: TObject); begin ToRecord (CusDaMa.QueryCus,'NextRun'); end; procedure TForm1.LastClick(Sender: TObject); begin ToRecord (CusDaMd.QueryCus,'LastRun'); end; function TFrom1.ToRecord(QueryDateSet : TQuery ; ActRecord : String ):Boolean; var CaseSet : String ; begin CaseSet := ActRecord; CusDaMd.QueryCus.Close; CusDaMd.QueryCus.SQL.Clear; case CaseSet of FirstRun : begin CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo = (select min(CustNo)from customer)'); end; PriorRun : begin CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo =(select max(CustNo)from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo <''' CusNo ''')'); end; NextRun : begin CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo =(select min(CustNo)from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo >''' CusNo ''')'); end; LestRun : begin CusDaMd.QueryCus.SQL.Add('select * from customer'); CusDaMd.QueryCus.SQL.Add('where CustNo = (select max(CustNo)from customer)'); end; end; CusDaMd.QueryCus.Open; CusNo := CusDaMd.QueryCus.FieldByName('CustNo').AsString; end; end.
likush
高階會員


發表:5
回覆:235
積分:103
註冊:2002-10-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-07 21:21:45 IP:220.134.xxx.xxx 未訂閱
小弟愚見 依您的作法,簡單點應將CusNo排序後,直接採用QueryCus.First等作法即可,再則Case不能用字串吧?如果要依您的作法來說的話應可用 function TForm1.ToRecord(QueryDateSet : TQuery ; ActRecord : Char ):Boolean; 然後 ToRecord (CusDaMa.QueryCus,'N')即可 ========================= 讀萬卷書~不如來K.TOP走一遭 =========================
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-08 14:16:24 IP:61.70.xxx.xxx 未訂閱
您好: 我幫您把程式整個改了一下,減少程式碼,也能達到您的需求,及沒考慮到的地方,您參考參考
 
procedure TForm1.zQueryWork(var Query:TAdoQuery;Str:String);
begin
Query.Close();
Query.SQL.Clear();
Query.SQL.Add(Str);
Query.Open();
end;    procedure TForm1.btnFirstClick(Sender: TObject);
begin
if (Sender=btnFirst) then
 zQueryWork(qryCust,'select * from cust where No = (select min(No)from cust)');
if (Sender=btnPrior) then
 zQueryWork(qryCust,'SELECT TOP 1 * FROM Cust ' 
                    'WHERE No<''' CustNo ''' ' 
                    'ORDER BY No DESC ');
if (Sender=btnNext) then
 zQueryWork(qryCust,'SELECT TOP 1 * FROM Cust ' 
                    'WHERE No>''' CustNo ''' ' 
                    'ORDER BY No Asc ');
if (Sender=btnLast) then
 zQueryWork(qryCust,'select * from cust where No = (select max(No)from cust)');
if (qryCust.IsEmpty) then
 zQueryWork(qryCust,'select * from cust where No = ''' CustNo '''');
CustNo:=qryCust.FieldByName('No').AsString;
end;    procedure TForm1.FormActivate(Sender: TObject);
begin
CustNo:='00001';
end;    
LearnDelphi
一般會員


發表:4
回覆:7
積分:2
註冊:2005-04-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-04-08 23:32:41 IP:218.162.xxx.xxx 未訂閱
謝謝likush,supman兩位的指導,我已經做出來了... 兩位都是對我function的觀念橋正很多.. 謝謝你們 likush謝謝你,我利用supman的做法做出來 你給我的觀念,方法也很重要..謝謝
系統時間:2024-11-24 18:40:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!