ตัวอย่างที่ผมลองทำครับ ดึงเฉพาะข้อมูล
unit RP504;
var
MainForm: TForm;
OKButton, SaveButton, PrintButton, ExitButton: TButton;
ds1, ds2: TDateEdit;
lds1, lds2, lcode, lid, lname,lpath: TLabel;
tcode, tid, tname,tpath: TEdit;
FAborting: boolean;
yymm:string;
rp:TTzDBF;
rphosp:TStringField;
rpdate:TStringField;
rpcase1:TStringField;
rpcase2:TStringField;
rpcase3:TStringField;
rpcase4:TStringField;
rpcase5:TStringField;
rpcase6:TStringField;
rpcase7:TStringField;
rpcase8:TStringField;
rpcase9:TStringField;
rpcase10:TStringField;
rpcase11:TStringField;
rpcase12:TStringField;
rpcase13:TStringField;
rpcase14:TStringField;
rpcase15:TStringField;
rpcase16:TStringField;
rpcase17:TStringField;
rpcase18:TStringField;
rpcase19:TStringField;
rpcase20:TStringField;
rpcase21:TStringField;
implementation
procedure OKClick(Sender: TObject);
var
sdate,edate:tdatetime;
tc:Tclientdataset;
begin
yymm:=formatdatetime('yymm',strtodate(ds2.text));
sdate:=ds1.text;
edate:=ds2.text;
tc:=TClientDataset.create(nil);
tc.data:=HOSxP_GetDataset('select a.*,ifnull(d.amount,0) as amount from rpt_504_name a left join '+
' (select b.id,count(b.id) as amount from rpt_504_code b,ovstdiag c '+
' where c.icd10 between b.code1 and b.code2 and c.icd10 is not null '+
' and c.vstdate between "'+formatdatetime('yyyy-mm-dd',sdate)+'" and "'+formatdatetime('yyyy-mm-dd',edate)+'"'+
' group by b.id) d on d.id=a.id'+
' order by a.id');
while not tc.eof do
begin
showmessage(tc.fieldbyname('id').asstring+'=>'+tc.fieldbyname('amount').asstring);
tc.next;
end;
end;
procedure ExitClick(Sender: TObject);
begin
mainform.close
end;
procedure Main;
begin
MainForm := TForm.Create(nil);
MainForm.top := 200;
MainForm.left := 200;
MainForm.Width := 400;
MainForm.Height := 400;
lcode := tlabel.create(mainform);
lcode.parent := mainform;
lcode.top := 10;
lcode.left := 10;
lcode.caption := 'Code';
tcode := tedit.create(mainform);
tcode.parent := mainform;
tcode.top := 10;
tcode.left := 70;
tcode.width := 85;
tcode.text := '110962100000';
lid := tlabel.create(mainform);
lid.parent := mainform;
lid.top := 35;
lid.left := 10;
lid.caption := 'Off_ID';
tid := tedit.create(mainform);
tid.parent := mainform;
tid.top := 35;
tid.left := 70;
tid.width := 40;
tid.text := VarToStr(GetSQLData('select hospitalcode from opdconfig'));
lname := tlabel.create(mainform);
lname.parent := mainform;
lname.top := 60;
lname.left := 10;
lname.caption := 'Name';
tname := tedit.create(mainform);
tname.parent := mainform;
tname.top := 60;
tname.left := 70;
tname.width := 200;
tname.text := VarToStr(GetSQLData('select hospitalname from opdconfig'));
lds1 := tlabel.create(mainform);
lds1.parent := mainform;
lds1.top := 85;
lds1.left := 10;
lds1.caption := 'Begin Date';
ds1 := TDateEdit.Create(MainForm);
ds1.parent := mainForm;
ds1.left := 70;
ds1.top := 85;
ds1.Width := 85;
ds1.text := now-formatdatetime('dd',now)+1;
lds2 := tlabel.create(mainform);
lds2.parent := mainform;
lds2.top := 85;
lds2.left := 200;
lds2.caption := 'End Date';
ds2 := TDateEdit.Create(MainForm);
ds2.parent := mainForm;
ds2.left := 270;
ds2.top := 85;
ds2.Width := 85;
ds2.text := now;
lpath := tlabel.create(mainform);
lpath.parent := mainform;
lpath.top := 110;
lpath.left := 10;
lpath.caption := 'Send To';
tpath := tedit.create(mainform);
tpath.parent := mainform;
tpath.top := 110;
tpath.left := 70;
tpath.width := 200;
tpath.text := 'C:\TEMP';
OKButton := TButton.Create(MainForm);
OKButton.parent := mainForm;
OKButton.left := 30;
OKButton.top := 180;
OKButton.Width := 60;
OKButton.caption := 'OK';
OKButton.OnClick := OKClick;
ExitButton := TButton.Create(MainForm);
ExitButton.parent := mainForm;
ExitButton.left := 140;
ExitButton.top := 180;
ExitButton.Width := 60;
ExitButton.caption := 'Exit';
ExitButton.OnClick := ExitClick;
MainForm.Caption := 'ÃÒ§ҹ 504';
MainForm.Showmodal;
MainForm.free;
end;
end.