begin..end 不遜於大括號。record + procedure/function = class。類本質是變數,Implementation 定義細節,Interface 告訴編譯器去哪裡找代碼。Form 間引用實為物件變數元素引用。Property(可讀寫)、Method(呼叫過程/函數)、Event(回調)。設計時在 Object Inspector 設 Property,運行時呼叫 Method。read GetX write SetX),非單純賦值。DisplayName 為中文、Transliterate=False 正確顯示中文。if Form2.ShowModal = mrOK then begin
Table1.DisableControls;
Table1.First;
while not Table1.EOF and (Pos(Form2.Edit1.Text, Table1Name.Value) = 0) do
Table1.Next;
Table1.EnableControls;
end;
private 區段,嚴禁在 class 定義外定義全域變數。begin 後縮排兩格,end 對齊對應 begin 欄位。begin..end 會自動清理)。FormCreate 前控件未建立不可引用;OnCreate 內直接用控件名(ListBox1)而非 Form1.ListBox1。OnCreate 不可引用其他 Form 變數(尚未建立)。ShowModal 阻塞,Show 非阻塞。Application.ProcessMessages 防假死。TTimer 觸發間隔若短於執行時間,下一次觸發會重入同一事件處理器,造成共享變數競態。類似地,Show 非模態視窗同時操作同一變數也會產生離奇 Bug。新手優先避開:Timer 事件首行設 Enabled := False,處理完再 True;傾向用 ShowModal。