var b: boolean;
begin
b := boolean(2); //這樣只是為了除錯//b := true;
if b = true then showmessage(』b = true』); //不建議//不安全
///
if b then showmessage(』b』); //建議//簡短
end;
var b: boolean;
begin
if edit1.text = 』是』 then //不建議//煩瑣
b := true
else b := false;
///
b := edit1.text = 』是』; //建議//簡短
end;
begin
querytemp.close;
querytemp.sql.text := 』select sum(金額) as 合計 from 銷售表』;
querytemp.open; //不建議//資料沒有關閉造成資源浪費
showmessage(query1.fieldbyname(』合計』).asstring);
/ querytemp.sql.text := 』select sum(金額) as 合計 from 銷售表』;
querytemp.open;
showmessage(query1.fieldbyname(』合計』).asstring);
querytemp.close; //建議用//使用完就關閉
end;
var
vrecordcount: integer;
begin
query1.sql.text := 』select * from table1』; //不建議//嚴重浪費資源,會取得很多不必要得資訊
query1.open;
vrecordcount := query1.recordcount;
query1.close;
/ query1.sql.text := 』select count(*) as 記錄數 from table1』; //建議//快速有效、只處理一條記錄
query1.open;
vrecordcount := query1.fieldbyname(』記錄數』).asinteger;
query1.close;
showmessage(inttostr(vrecordcount));
end;
begin
table1.edit;
table1.fieldbyname(』姓名』).asstring := edit1.text; //不建議
table1.fieldbyname(』日期』).asdatetime := date;
/ table1[』姓名』] := edit1.text; //建議//簡短、擴充性好
姓名』] := edit1.text; //borland建議的方法。以及paramvalues
table1[』日期』] := date;
end;
begin
edit1.parent := form1; //不建議//form1只是乙個變數//如果沒有分配資源怎麼辦?
///
edit1.parent := self; //建議
end;
var
i: integer;
begin
query1.first;
for i := 0 to query1.recordcount - 1 do begin //不建議//容易被影響
query1.next;
{};
end;
/ query1.first;
while not query1.eof do begin //建議
query1.next;
end;
end;
procedure tform1.edit1change(sender: tobject);
begin
if edit1.text = 』』 then //不建議
edit1.color := clred;
///
if tedit(sender).text = 』』 then //建議//複製到editxchange中很方便
tedit(sender).color := clred;
end;
var
i: integer;
begin
i := strtoint(edit1.text); //不建議
///
i := strtointdef(edit1.text, 0);//建議//參考strtofloatdef,strtodatedef....不過這些只有delphi6才有
end;
var
i: integer;
a: array[0..9] of integer;
begin
for i := 0 to 9 do //不建議
a[i] := i;
///
for i := low(a) to high(a) do //建議//擴充性好
a[i] := i;
end;
begin
caption := copy(edit1.text, 3, length(edit1.text) - 3 + 1); //不建議
///
caption := copy(edit1.text, 3, maxint); //建議//嘻嘻,少計算一次
end;
function funcname: boolean;
begin
funcname := true; //不建議//並且放在賦值號右邊不能當普通變數
///
result := true; //建議//擴充性好
end;
function funcsum(a: array of integer): integer;
var i: integer;
begin
result := 0;
for i := low(a) to high(a) do
result := result + a[i]; //可不能用 funcsum := funcsum + a[i];
end;
var
vstringlist: tstringlist;
begin
vstringlist := tstringlist.create;
vstringlist.loadfromfile(』c:\temp.txt』);
showmessage(vstringlist.text);
vstringlist.free; //不建議//如果出現異常資源將無法釋放
///
vstringlist := tstringlist.create;
try
vstringlist.loadfromfile(』c:\temp.txt』);
showmessage(vstringlist.text);
finally //建議//即使出現exit都會執行
vstringlist.free;
end;
end;
//其他情況1
begin
screen.cursor := crhourglass;
try
finally
screen.cursor := crdefault;
end;
end;
//其他情況2
begin
query1.disablecontrols;
try
finally
query1.enablecontrols;
end;
end;
Delphi中建議使用的語句
var b boolean begin b boolean 2 這樣只是為了除錯 b true if b true then showmessage b true 不建議 不安全 if b then showmessage b 建議 簡短 end var b boolean begin if edi...
Delphi中的INI檔案程式設計
tinifile類中定義了許多成員函式,這裡介紹幾個使用頻率較高的成員函式 create 函式定義為 constructor create const filename string 該函式建立tinifile類的物件。引數filename是要讀寫的初始化檔名。若讀寫的檔案在windows的目錄裡 ...
Delphi中的INI檔案程式設計
delphi 中的ini 檔案程式設計 ini 檔案在系統配置及應用程式引數儲存與設定方面,具有很重要的作用,所以視覺化的程式設計一族,如vb vc vfp delphi 等都提供了讀寫 ini檔案的方法,其中 delphi 中操作ini 檔案,最為簡潔,這是因為 delphi3 提供了乙個 tin...