2013/07/15

Delphi2009的httpsrvr.dll有Bug

TWebConnection如果使用Delphi2009所提供的httpsrvr.dll時會出現「Access violation dsnapcon120.bpl」的問題。

不過因為實在是太懶,不想進Source來Debug。

所以借了Delphi7和DelphiXE的httpsrvr.dll來使用,完全沒有出現上述的問題。

可見,這就是Delphi2009的Bug。

2013/07/08

How to change font size on MainMenu / ActionMainMenuBar in Delphi

其實比預期得還要簡單!
原來在TForm上有一個屬性:MenuFont。

只要改變它就可以囉!

TMainMenu 和 TActionMainMenuBar 適用!

Ex:
procedure TForm2.FormCreate(Sender: TObject);
begin
  Screen.MenuFont.Name := 'Arial Black';
end;

參考資料:How can I change the fontsize of the mainmenu items in Delphi?

2013/07/06

Create an item in a TActionMainMenuBar at runtime

從Reference參考得來的作法,原來之前做出來的Menu無法Enabled的問題在於「沒有把TAction」裝在Menu的第一層,所以就會變成無法啟用,可是這在Design Mode下卻可以正常開啟,果然這其中一定有什麼奧秘是我不知道的啊!

不過,暫時先這樣吧!

底下是失敗的例子:
var
  actItem, actItemA: TActionClientItem;
  Clients: TActionClients;
begin
  Clients := ActionMainMenuBar1.ActionClient.Items;
  actItemA := Clients.Add;
  actItemA.Caption := '&Edit';
  actItem := actItemA.Items.Add;
  actItem.Action := EditCut1;
  actItem.Visible := True;
  actItemA.Visible := True;

正確的作法應該是:
var
  actItem: TActionClientItem;
  actRun,actRun2: TAction;
begin
  actRun := TAction.Create(Self);
  actRun.Name := 'H1';
  actRun.Category := 'HELLO';
  actRun.OnExecute := Action1Execute;
  actRun2 := TAction.Create(Self);
  actRun2.Name := 'H2';
  actRun2.Category := 'HELLO';
  actRun2.OnExecute := Action1Execute;
  with ActionMainMenuBar1.ActionClient.Items.Add do
  begin
    Caption := 'HELLO';
    Action := actRun;  // 每一層一定都要掛載TAction才會把MenuItem Enable
    with Items.Add do
    begin
      Caption := 'HELLO2';
      Action := actRun2;
      with Items.Add do
      begin
        Action := actRun;
      end;
    end;
    Visible := True;
  end;


Reference: Delphi Knowledge Base: Create an item in a TActionMainMenuBar at runtime

2013/06/14

ClientDataSet上使用GROUP BY篩選

ClientDataSet對已經收到的資料集是不能再下SQL語法篩選的。

不過,把GROUP BY的邏輯想通應該也可以如法泡製。

直接把結果轉出來吧!

2013/06/13

Delphi繼承的寫法

底下的連結提供了相當多的解法,有時需要改裝一下TCustomForm時可以來參考使用。

資料來源:Delphi/pascal: overloading a constructor with a different prototype

Delphi 2009 raises Exception in DBX: Unknown Driver XXX

在Design Mode下使用TSQLConnection,設定完成後也可以正常連線,可是在Runtime硬是出現「Unknown Driver: MSSQL」。

其實這只要在uses區手動加入「DBXDynalink」,就可以用了。

資料來源:Delphi 2009 raises Exception "Unknown Driver: Devart..."

2013/06/10

EAccessViolation in function CreateProcess in Delphi 2009

很有趣的,我也遇到了這件事情,明明 CreateProcess 這函式在Delphi 7時就正常,到了Delphi 2009就出怪手了。

原因就是出在Unicode……解法轉貼如下: