Einzelnen Beitrag anzeigen

hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.276 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: TSaveDialog, OnTypeChange, FileName zur Laufzeit ändern

  Alt 29. Jul 2009, 15:21
Hallo,

wer lange sucht.

Delphi-Quellcode:
function GetWndText(Ctrl:HWnd): String;
var
  i : Integer;
begin
  Result:= '';

  try
    i:=SendMessage(Ctrl,WM_GETTEXTLENGTH,0,0);
    SetLength(Result,i);
    SendMessage(Ctrl,WM_GETTEXT,i+1,DWord(Result));
  except
  end;
end; { GetWndText }  


procedure TEditGrid.DoCommonExportToXLS_TypeChange(Sender: TObject);
var
  Ctrl : HWnd;
  Item : Longint;
  sFileName : String;
  sFileExt : String;
begin
 { portion from [url]http://newsgroups.derkeiler.com/Archive/De/de.comp.lang.delphi.misc/2007-05/msg00169.html[/url] }
  try
    Item := $47C;

    with (Sender as TSaveDialog) do
    begin
      if FilterIndex=2 then
      begin
       // filter is ".xlsx"

        // Set a new default extension
        // The control with ID=$480 is the Filename edit field
        // Man muss $47C nehmen !!!!!!!!!!!!
        Ctrl:= GetDlgItem(Handle, Item);
        // The following block is necessary due to a bug in Delphi:
        // TSaveDialog.Handle is not always the Handle of the dialog
        if Ctrl=0 then Ctrl:=GetDlgItem(GetParent(Handle), Item);
        if Ctrl=0 then exit;

      // Get its text, change the extension, and write back
        sFileName:= GetWndText(Ctrl);
        sFileExt:= ExtractFileExt(sFileExt);
        if sFileExt<>'.xlsxthen
        begin
          sFileName:= ChangeFileExt(sFileName, '.xlsx');

          SendMessage(Ctrl,WM_SETTEXT,0,DWord(sFileName));
        end;
      end;
    end; { with (Sender as TSaveDialog) do }
  except
  end;
end; { TEditGrid.DoCommonExportToXLS_TypeChange }

      ExcelFileDialog.OnTypeChange:= DoCommonExportToXLS_TypeChange;
Original-Link im Quellcode


Heiko
Heiko
  Mit Zitat antworten Zitat