2023年3月29日 星期三

Delphi 要如何取得DLL的檔案名稱

 
var
  DLLFileName: array [0..MAX_PATH] of Char;
begin
  GetModuleFileName(HInstance, DLLFileName, Length(DLLFileName));
  ShowMessage(DLLFileName);
end;

CharGPT 的回應

2023年3月28日 星期二

2023年3月23日 星期四

Delphi ClientDataset GetGroupState

GetGroupState

ClientDataset 需先建立IndexDef,GetGroupState代入GroupingLevel,可以取得資料列在Group中所屬的狀態gbFirst、gbMiddle、gbLast


procedure TForm1.FormCreate(Sender: TObject);
var inxIndex:TIndexDef;
  aggAggregate:TAggregate;
begin
  //Create Index
  inxIndex := ClientDataSet1.IndexDefs.AddIndexDef;
  inxIndex.Name := 'Index1';
  inxIndex.Fields := 'Field1;Field2';
  inxIndex.GroupingLevel := 2; //群組的層級,取決於Fields的數量
  ClientDataset1.IndexName := inxIndex.Name;
end;

procedure TForm1.ClientDataSet1Field1GetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  //TGroupPosInd = (gbFirst, gbMiddle, gbLast);
  if gbFirst in ClientDataset1.GetGroupState(1) then
    Text := Sender.AsString
  else
    Text := '';
end;


原資料


gbFirst in ClientDataset1.GetGroupState(1)

gbMiddle in ClientDataset1.GetGroupState(1)

gbLast in ClientDataset1.GetGroupState(1)


ClientDataset Methods 說明

Datasnap.DBClient.TClientDataSet Methods


Delphi ClientDataset Aggregates & Index 分組合計

 


procedure TForm1.FormCreate(Sender: TObject);
var inxIndex:TIndexDef;
  aggAggregate:TAggregate;
begin
  with ClientDataSet1 do
  begin
    //Create Dataset
    FieldDefs.Add('Field1', ftString, 20);
    FieldDefs.Add('Field2', ftString, 20);
    FieldDefs.Add('Qty', ftInteger);
    CreateDataSet;
    //Append Data
    AppendRecord(['1', '1', 10]);
    AppendRecord(['1', '1', 30]);
    AppendRecord(['1', '2', 50]);
    AppendRecord(['2', '2', 70]);
    AppendRecord(['2', '1', 90]);
  end;

  //Create Index
  inxIndex := ClientDataSet1.IndexDefs.AddIndexDef;
  inxIndex.Name := 'Index1';
  inxIndex.Fields := 'Field1;Field2';
  inxIndex.GroupingLevel := 2; //群組的層級,取決於Fields的數量
  ClientDataset1.IndexName := inxIndex.Name;

  //Create Aggregates
  aggAggregate := ClientDataset1.Aggregates.Add;
  aggAggregate.AggregateName := 'Aggregate0';
  aggAggregate.Expression := 'Sum(Qty)';
  //針對指定的群組層級做統計. 0:全部, Dataset可以不指定IndexName
  aggAggregate.GroupingLevel := 0;
  aggAggregate.IndexName := inxIndex.Name;
  aggAggregate.Active := True;

  aggAggregate := ClientDataset1.Aggregates.Add;
  aggAggregate.AggregateName := 'Aggregate1';
  aggAggregate.Expression := 'Sum(Qty)';
  //針對指定的群組層級做統計, Ex: Gropup by Field1
  aggAggregate.GroupingLevel := 1;
  aggAggregate.IndexName := inxIndex.Name;
  aggAggregate.Active := True;

  aggAggregate := ClientDataset1.Aggregates.Add;
  aggAggregate.AggregateName := 'Aggregate2';
  aggAggregate.Expression := 'Sum(Qty)';
  //針對指定的群組層級做統計, Ex: Group by Field1, Field2
  aggAggregate.GroupingLevel := 2;
  aggAggregate.IndexName := inxIndex.Name;
  aggAggregate.Active := True;

  aggAggregate := ClientDataset1.Aggregates.Add;
  aggAggregate.AggregateName := 'Aggregate3';
  aggAggregate.Expression := 'Max(Qty)';
  //針對指定的群組層級做統計, Ex: Group by Field1
  aggAggregate.GroupingLevel := 1;
  aggAggregate.IndexName := inxIndex.Name;
  aggAggregate.Active := True;

  Memo1.Clear;
  Memo1.Lines.Add('Aggregate0 (Sum(Qty)) = '+VarToStr(ClientDataSet1.Aggregates.Find('Aggregate0').Value));
  Memo1.Lines.Add('Aggregate1 (Sum(Qty) Group by Field1) = '+VarToStr(ClientDataSet1.Aggregates.Find('Aggregate1').Value));
  Memo1.Lines.Add('Aggregate2 (Sum(Qty) Group by Field1, Field2) = '+VarToStr(ClientDataSet1.Aggregates.Find('Aggregate2').Value));
  Memo1.Lines.Add('Aggregate3 (Max(Qty) Group by Field1) = '+VarToStr(ClientDataSet1.Aggregates.Find('Aggregate3').Value));
end;

2023年3月15日 星期三

Delphi ForceDirectories 建立資料夾

 

ForceDirectories     建置到指定的層級目錄 

Ex : 
ForceDirectories ('C:\Temp\Sub1\Sub2');
ForceDirectories ('\\10.10.10.10\Temp\Sub1\Sub2');

 

2023年3月9日 星期四

SQL PIVOT 直向資料內容轉橫向輸出


Select *
  (
    Select Field01, Field02, Field03, Field04
    From Table1
  ) a
Pivot
  ( 
    Sum(Field05) /*合計值*/
    For Field04 in ([Value01], [Value02], [Value03], [Value04])  /*橫向表頭*/
  ) b




2023年3月6日 星期一

ScorllBar 系統寬高

 
ScrollBar High
    GetSystemMetrics(SM_CYHSCROLL)


ScrollBar Width
    GetSystemMetrics(SM_CXVSCROLL)