Liste der FAQ Einträge "Borland VCL"
Ende einer externen Anwendung abwarten
procedure TForm1.Button1Click(Sender: TObject);
Var Handle : Word;
begin
Handle := WinExec('Notepad',SW_ShowNormal);
While GetModuleUsage(Handle) > 0 Do
Begin
Enabled := False;
Application.Processmessages;
End;
Enabled := True;
end;
What do I need in my uses clause to use the WinExecAndWait function
{ by Pat Ritchey }
function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
StrPCopy(zAppName,FileName);
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then Result := -1
else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,Result);
CloseHandle( ProcessInfo.hProcess );
CloseHandle( ProcessInfo.hThread );
Result := 0;
end;
end;
Variablen sollen nach Verlassen der procedure ihren Wert erhalten
procedure TForm1.Button1Click(Sender: TObject);
Const Counter: Integer = 0;
begin
..
Programm nur einmal starten
USES WinProcs, WinTypes;
var PrevInstance: hWnd;
Const AppName = 'Meine Applikation'; // Titel für Ihre Anwendung, an dem diese eindeutig erkannt wird
PrevInstance := FindWindow('TApplication', AppName); // ermitteln der Instanz
if PrevInstance <> 0 then
if IsIconic(PrevInstance)
then ShowWindow(PrevInstance, sw_Restore)
else BringWindowToTop(PrevInstance)
else
begin
Application.Title := AppName;
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
wie ich in einem TEdit-Feld bestimmen kann, wo sich der Schreibcursor gerade befindet.
OH, TEdit => Eigenschaften;
Durch Lesen von SelStart wird die Position des ersten markierten Zeichens
festgelegt, wobei 0 das erste Zeichen angibt. Ist kein markierter Text
vorhanden, bezeichnet SelStart die Position des Cursors
Klasse zum Behandeln von Mausklicks auf Statusbars Panels.
Nur über abgeleitete StatusBar:
type
TpcStatusBar = class(TStatusBar)
private
protected procedure MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer); override;
public
clickonpanel: integer;
end;
procedure Register;
implementation
procedure TpcStatusBar.MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
var i, w: Integer;
begin
w:= 0;i:= -1;
repeat
inc(i);
w := w + panels[i].width;
until w > x;
clickonpanel:= i;
inherited;
end;
procedure Register;
begin
RegisterComponents('Beispiele', [TpcStatusBar]);
end;
RxFormStorage personifizieren.
zur Entwicklungszeit setzen:
FormStorage.UseRegistry := TRUE
FormStorage.Active := FALSE
zur Laufzeit in Form.OnCreate:
FormStorage.IniFileName := 'Software\Firma\Modul';
FormStorage.IniSection := User_name + '\' + Form.Name;
FormStorage.Active := TRUE;
ListBox mit definierten Wert selektieren, deren Elemente bekannt sind
Die Listbox hat die Eigenschaft Style = csDropDownList, deshalb geht ListBox1.Text := value nicht.
procedure ListBox1ItemAtValue(value: string);
var i: integer;
begin
for i := 0 to ListBox1.Items.Count-1 do begin
if ListBox1.Items[i] = value then begin
ListBox1.ItemIndex := i;
break;
end;
end;
end;
ComboBox mit einem zusätzlichen ID Wert (integer) füllen
Häufig wird bei Datenbankanwendungen eine Referenz geführt. In der Maske soll
dazu aber der Klartext dargestellt werden. In der ComboBox müssen nun beide Werte abgelegt werden,
der Text und die Referenz, die häufig ein Integerwert ist. Dazu wird die Items Eigenschaft Objects benutzt.
1. Füllen der ComboBox
[öffnen einer TDataSource mit den Feldern my_text, my_id..]
while not EOF do begin
ComboBox.Items.Add(trim(FieldByName('my_text').AsString, TObject(FieldByName('my_id').AsInteger));
next;
end;
2. Auslesen des Wertes
Wurde der Wert nur per ComboBox.Text gefüllt, dann steht der ItemIndex noch falsch:
ComboBox.ItemIndex := ComboBox.Items.IndexOf( ComboBox.Text );
Lesen des zugehörigen ID Wertes:
id := integer(ComboBox.Items.Objects[ ComboBox.ItemIndex ]);
Splashscreen
begin
Application.Initialize;
with TForm1.Create(nil) do
try
begin
SplashForm:= TSplashForm.Create(Application);
SplashForm.Show;
SplashForm.Update;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
SplashForm.Hide;
SplashForm.Free;
end;
finally
Free;
end;
Application.Run;
end.
DLL dynamisch laden
uses Windows, ...;
type
TTimeRec = record ... end;
TGetTime = procedure(var Time: TTimeRec);
THandle = integer;
var
Time: TTimeRec;
Handle: THandle;
GetTime: TGetTime;
...
begin
Handle := LoadLibrary('datetime.dll');
if Handle <> 0 then begin
@GetTime := GetProcAdress(Handle, 'GetTime');
if @GetTime <> nil then begin
GetTime(Time);
...
end;
FreeLibrary(Hanlde);
end;
end;
Die DLL wird erst bei der Ausführung des Quelltextes geladen. Das Programm läuft auch, wenn die
DLL nicht zur Verfügung steht.
Kein Hauptfenster anzeigen
Beim OnCrete Event des Hauptformulars folgende Zeile eingügen:
Application.ShowMainForm := false;
DLL Name ähnlich Application.ExeName ermitteln
Quelle: www.delphi3000.com/articles/article_3283.asp
function GetRealExeName: string;
var EXEName: array[0..MAX_PATH] of char;
begin
fillchar(ExeName, SizeOf(ExeName), #0);
GetModuleFileName(HInstance, ExeName, MAX_PATH);
result := ExeName;
end;