ทำอย่างไรจะใช้ ADO ในการสร้าง procedure
ถ้าสร้างเป็น Button เวลา Click แล้วจะรันได้ แต่ถ้าเปลี่ยนเป็น Procedure เวลารันมันฟ้องว่า Undeclared indentifier: 'ADOTBuySell' Undeclared indentifier: 'ADOTBuySellQuantity'
รายละเอียดตามข้างล่างนี้ Button เขียนดังนี้ procedure TForm1.btnChkClick(Sender: TObject); Var SumQty:Double; begin ADOTBuySell.First; if (ADOTBuySellQuantity.Value<0) then Showmessage('Cannot sell when you have no Stock') else begin SumQty:=0; repeat SumQty:=ADOTBuySellQuantity.Value+SumQty; ADOTBuySell.Next; if (ADOTBuySellQuantity.Value<0) and (-ADOTBuySellQuantity.Value>SumQty) then Showmessage('Cannot sell when you have no Stock'); until ((ADOTBuySellQuantity.Value<0) and (-ADOTBuySellQuantity.Value>SumQty)) or ADOTbuySell.Eof=True; end; end;
Procedure เขียนดังนี้ var Form1: TForm1; procedure OnhandChk;
implementation
uses EditData;
{$R *.dfm}
procedure OnhandChk; Var SumQty:Double; begin ADOTBuySell.First; if (ADOTBuySellQuantity.Value<0) then Showmessage('Cannot sell when you have no Stock') else begin SumQty:=0; repeat SumQty:=ADOTBuySellQuantity.Value+SumQty; ADOTBuySell.Next; if (ADOTBuySellQuantity.Value<0) and (-ADOTBuySellQuantity.Value>SumQty) then Showmessage('Cannot sell when you have no Stock'); until ((ADOTBuySellQuantity.Value<0) and (-ADOTBuySellQuantity.Value>SumQty)) or ADOTbuySell.Eof=True; end; end;
|