Programlama yapalım ve Öğrenelim. - Delphi Eğitim174
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

neoturk: ...Get the modify date of files ?...

function GetFileModifyDate(FileName: string): TDateTime;

var

  h: THandle;

  Struct: TOFSTRUCT;

  lastwrite: Integer;

  t: TDateTime;

begin

  h := OpenFile(PChar(FileName), Struct, OF_SHARE_DENY_NONE);

  try

    if h <> HFILE_ERROR then

    begin

      lastwrite := FileGetDate(h);

      Result    := FileDateToDateTime(lastwrite);

    end;

  finally

    CloseHandle(h);

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if Opendialog1.Execute then

    label1.Caption := FormatDateTime('dddd, d. mmmm yyyy hh:mm:ss',

      GetFileModifyDate(Opendialog1.FileName));

end;

 

Delphi - .....................................

 

neoturk: ...Read line-by-line and modify a textfile ?...

procedure TForm1.Button1Click(Sender: TObject);

var

  i, z: Integer;

  f: TextFile;

  t: string;

  Data: array of string;

begin

  if OpenDialog1.Execute then

  begin

    //Read line by line in to the array data

    AssignFile(f, OpenDialog1.FileName);

    Reset(f);

    z := 0;

    SetLength(Data, 0);

    //Repeat for each line until end of file

    repeat

      Inc(z);

      readln(f, t);

      SetLength(Data, Length(Data) + Length(t));

      Data[z] := t;

    until EOF(f);

 

    SetLength(Data, Length(Data) + 3 * z);

    //Add to each line the line number

    for i := 1 to z do Data[i] := IntToStr(i) + ' ' + Data[i];

    SetLength(Data, Length(Data) + 2);

    //Add a carriage return and line feed

    Data[1] := Data[1] + #13 + #10;

    i       := Length(Data[5]);

    Data[5] := '';

    SetLength(Data, Length(Data) - i);

    //create a new textfile with the new data

    AssignFile(f, OpenDialog1.FileName + '2');

    ReWrite(f);

    //write all lines

    for i := 1 to z do writeln(f, Data[i]);

    //save file and close it

    CloseFile(f);

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Read line-by-line and modify a textfile ?...

procedure TForm1.Button1Click(Sender: TObject);

var

  i, z: Integer;

  f: TextFile;

  t: string;

  Data: array of string;

begin

  if OpenDialog1.Execute then

  begin

    //Read line by line in to the array data

    AssignFile(f, OpenDialog1.FileName);

    Reset(f);

    z := 0;

    SetLength(Data, 0);

    //Repeat for each line until end of file

    repeat

      Inc(z);

      readln(f, t);

      SetLength(Data, Length(Data) + Length(t));

      Data[z] := t;

    until EOF(f);

 

    SetLength(Data, Length(Data) + 3 * z);

    //Add to each line the line number

    for i := 1 to z do Data[i] := IntToStr(i) + ' ' + Data[i];

    SetLength(Data, Length(Data) + 2);

    //Add a carriage return and line feed

    Data[1] := Data[1] + #13 + #10;

    i       := Length(Data[5]);

    Data[5] := '';

    SetLength(Data, Length(Data) - i);

    //create a new textfile with the new data

    AssignFile(f, OpenDialog1.FileName + '2');

    ReWrite(f);

    //write all lines

    for i := 1 to z do writeln(f, Data[i]);

    //save file and close it

    CloseFile(f);

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Open a url or a file with the associated application ?...

To open a file of your choice with the application associated

with this files i.e a website but all other documents as

well you only need to call the url.dll with a rundll32 command.

Notice the Expression FileProtocolHandler is case sensitive:

 

Um eine Datei, z.B. eine Webseite oder auch jedes andere

beliebige Dokument/Datei mit dem assoziierten Programm aufzurufen,

bedarf es nur einem Aufruf der url.dll Datei mithilfe von Rundll32.

Bei FileProtocolHandler Groß- und Kleinschribung beachten:

 

WinExec(PChar('rundll32 url.dll,

        FileProtocolHandler http://www.superonline.com'),

        SW_MAXIMIZE);

 

Delphi - .....................................

 

neoturk: ...Open a url or a file with the associated application ?...

To open a file of your choice with the application associated

with this files i.e a website but all other documents as

well you only need to call the url.dll with a rundll32 command.

Notice the Expression FileProtocolHandler is case sensitive:

 

Um eine Datei, z.B. eine Webseite oder auch jedes andere

beliebige Dokument/Datei mit dem assoziierten Programm aufzurufen,

bedarf es nur einem Aufruf der url.dll Datei mithilfe von Rundll32.

Bei FileProtocolHandler Groß- und Kleinschribung beachten:

 

WinExec(PChar('rundll32 url.dll,

        FileProtocolHandler http://www.superonline.com'),

        SW_MAXIMIZE);

 

Delphi - .....................................

 

neoturk: ...Get a list of all running exe-files- check if a exe-file is running ?...

uses

  Psapi, tlhelp32;

 

procedure CreateWin9xProcessList(List: TstringList);

var

  hSnapShot: THandle;

  ProcInfo: TProcessEntry32;

begin

  if List = nil then Exit;

  hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);

  if (hSnapShot <> THandle(-1)) then

  begin

    ProcInfo.dwSize := SizeOf(ProcInfo);

    if (Process32First(hSnapshot, ProcInfo)) then

    begin

      List.Add(ProcInfo.szExeFile);

      while (Process32Next(hSnapShot, ProcInfo)) do

        List.Add(ProcInfo.szExeFile);

    end;

    CloseHandle(hSnapShot);

  end;

end;

 

procedure CreateWinNTProcessList(List: TstringList);

var

  PIDArray: array [0..1023] of DWORD;

  cb: DWORD;

  I: Integer;

  ProcCount: Integer;

  hMod: HMODULE;

  hProcess: THandle;

  ModuleName: array [0..300] of Char;

begin

  if List = nil then Exit;

  EnumProcesses(@PIDArray, SizeOf(PIDArray), cb);

  ProcCount := cb div SizeOf(DWORD);

  for I := 0 to ProcCount - 1 do

  begin

    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or

      PROCESS_VM_READ,

      False,

      PIDArray[I]);

    if (hProcess <> 0) then

    begin

      EnumProcessModules(hProcess, @hMod, SizeOf(hMod), cb);

      GetModuleFilenameEx(hProcess, hMod, ModuleName, SizeOf(ModuleName));

      List.Add(ModuleName);

      CloseHandle(hProcess);

    end;

  end;

end;

 

procedure GetProcessList(var List: TstringList);

var

  ovi: TOSVersionInfo;

begin

  if List = nil then Exit;

  ovi.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);

  GetVersionEx(ovi);

  case ovi.dwPlatformId of

    VER_PLATFORM_WIN32_WINDOWS: CreateWin9xProcessList(List);

    VER_PLATFORM_WIN32_NT: CreateWinNTProcessList(List);

  end

end;

 

function EXE_Running(FileName: string; bFullpath: Boolean): Boolean;

var

  i: Integer;

  MyProcList: TstringList;

begin

  MyProcList := TStringList.Create;

  try

    GetProcessList(MyProcList);

    Result := False;

    if MyProcList = nil then Exit;

    for i := 0 to MyProcList.Count - 1 do

    begin

      if not bFullpath then

      begin

        if CompareText(ExtractFileName(MyProcList.Strings[i]), FileName) = 0 then

          Result := True

      end

      else if CompareText(MyProcList.strings[i], FileName) = 0 then Result := True;

      if Result then Break;

    end;

  finally

    MyProcList.Free;

  end;

end;

 

 

// Example 1: Is a Exe-File running ?

procedure TForm1.Button1Click(Sender: TObject);

begin

  if EXE_Running('Notepad.exe', False) then

    ShowMessage('EXE is running')

  else

    ShowMessage('EXE is not running');

end;

 

 

// Example 2: List running Exe-Files

procedure TForm1.Button3Click(Sender: TObject);

var

  i: Integer;

  MyProcList: TstringList;

begin

  MyProcList := TStringList.Create;

  try

    GetProcessList(MyProcList);

    if MyProcList = nil then Exit;

    for i := 0 to MyProcList.Count - 1 do

      ListBox1.Items.Add(MyProcList.Strings[i]);

  finally

    MyProcList.Free;

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Get a list of all running exe-files- check if a exe-file is running ?...

uses

  Psapi, tlhelp32;

 

procedure CreateWin9xProcessList(List: TstringList);

var

  hSnapShot: THandle;

  ProcInfo: TProcessEntry32;

begin

  if List = nil then Exit;

  hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);

  if (hSnapShot <> THandle(-1)) then

  begin

    ProcInfo.dwSize := SizeOf(ProcInfo);

    if (Process32First(hSnapshot, ProcInfo)) then

    begin

      List.Add(ProcInfo.szExeFile);

      while (Process32Next(hSnapShot, ProcInfo)) do

        List.Add(ProcInfo.szExeFile);

    end;

    CloseHandle(hSnapShot);

  end;

end;

 

procedure CreateWinNTProcessList(List: TstringList);

var

  PIDArray: array [0..1023] of DWORD;

  cb: DWORD;

  I: Integer;

  ProcCount: Integer;

  hMod: HMODULE;

  hProcess: THandle;

  ModuleName: array [0..300] of Char;

begin

  if List = nil then Exit;

  EnumProcesses(@PIDArray, SizeOf(PIDArray), cb);

  ProcCount := cb div SizeOf(DWORD);

  for I := 0 to ProcCount - 1 do

  begin

    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or

      PROCESS_VM_READ,

      False,

      PIDArray[I]);

    if (hProcess <> 0) then

    begin

      EnumProcessModules(hProcess, @hMod, SizeOf(hMod), cb);

      GetModuleFilenameEx(hProcess, hMod, ModuleName, SizeOf(ModuleName));

      List.Add(ModuleName);

      CloseHandle(hProcess);

    end;

  end;

end;

 

procedure GetProcessList(var List: TstringList);

var

  ovi: TOSVersionInfo;

begin

  if List = nil then Exit;

  ovi.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);

  GetVersionEx(ovi);

  case ovi.dwPlatformId of

    VER_PLATFORM_WIN32_WINDOWS: CreateWin9xProcessList(List);

    VER_PLATFORM_WIN32_NT: CreateWinNTProcessList(List);

  end

end;

 

function EXE_Running(FileName: string; bFullpath: Boolean): Boolean;

var

  i: Integer;

  MyProcList: TstringList;

begin

  MyProcList := TStringList.Create;

  try

    GetProcessList(MyProcList);

    Result := False;

    if MyProcList = nil then Exit;

    for i := 0 to MyProcList.Count - 1 do

    begin

      if not bFullpath then

      begin

        if CompareText(ExtractFileName(MyProcList.Strings[i]), FileName) = 0 then

          Result := True

      end

      else if CompareText(MyProcList.strings[i], FileName) = 0 then Result := True;

      if Result then Break;

    end;

  finally

    MyProcList.Free;

  end;

end;

 

 

// Example 1: Is a Exe-File running ?

procedure TForm1.Button1Click(Sender: TObject);

begin

  if EXE_Running('Notepad.exe', False) then

    ShowMessage('EXE is running')

  else

    ShowMessage('EXE is not running');

end;

 

 

// Example 2: List running Exe-Files

procedure TForm1.Button3Click(Sender: TObject);

var

  i: Integer;

  MyProcList: TstringList;

begin

  MyProcList := TStringList.Create;

  try

    GetProcessList(MyProcList);

    if MyProcList = nil then Exit;

    for i := 0 to MyProcList.Count - 1 do

      ListBox1.Items.Add(MyProcList.Strings[i]);

  finally

    MyProcList.Free;

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Include a exe-file in your application and execute it ?...

1.

Start notepad and create a .rc-file that looks like this:

Starte Notepad und erstelle ein .rc-file, das etwa so aussieht:

 

TESTFILE EXEFILE C:WindowsNotepad.exe

 

(Make sure that the Path to your Exe-File is correct!)

(Stelle sicher, dass der Pfad zur Exe-Datei korrekt ist!)

 

2.

Save it as myres.rc

Speichere es als myres.rc

 

3.

Compile the file with brcc32.exe

(in your Delphi-bin directory) to get myres.res

Kompiliere die Datei mit brcc32.exe

(Im Delphi-bin Verzeichnis) um die Datei myres.res zu erhalten.

 

4.

Copy myres.res to your Project directory.

Kopiere myres.res in das entsprechende Projekt-Verzeichnis.

 

5.

In your unit write the following:

In der unit, schreibe etwa das folgende:

 

 

var

  Form1: TForm1;

  NOTEPAD_FILE: string;

 

implementation

 

{$R *.DFM}

{$R MYRES.RES}

 

function GetTempDir: string;

var

  Buffer: array[0..MAX_PATH] of Char;

begin

  GetTempPath(SizeOf(Buffer) - 1, Buffer);

  Result := StrPas(Buffer);

end;

 

// Extract the Resource

function ExtractRes(ResType, ResName, ResNewName: string): Boolean;

var

  Res: TResourceStream;

begin

  Result := False;

  Res := TResourceStream.Create(Hinstance, Resname, PChar(ResType));

  try

    Res.SavetoFile(ResNewName);

    Result := True;

  finally

    Res.Free;

  end;

end;

 

// Execute the file

procedure ShellExecute_AndWait(FileName: string);

var

  exInfo: TShellExecuteInfo;

  Ph: DWORD;

begin

  FillChar(exInfo, SizeOf(exInfo), 0);

  with exInfo do

  begin

    cbSize := SizeOf(exInfo);

    fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;

    Wnd := GetActiveWindow();

    ExInfo.lpVerb := 'open';

    lpFile := PChar(FileName);

    nShow := SW_SHOWNORMAL;

  end;

  if ShellExecuteEx(@exInfo) then

  begin

    Ph := exInfo.HProcess;

  end

  else

  begin

    ShowMessage(SysErrorMessage(GetLastError));

    Exit;

  end;

  while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do

    Application.ProcessMessages;

  CloseHandle(Ph);

end;

 

// To Test it

procedure TForm1.Button1Click(Sender: TObject);

begin

  if ExtractRes('EXEFILE', 'TESTFILE', NOTEPAD_FILE) then

    if FileExists(NOTEPAD_FILE) then

    begin

      ShellExecute_AndWait(NOTEPAD_FILE);

      ShowMessage('Notepad finished!');

      DeleteFile(NOTEPAD_FILE);

    end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  NOTEPAD_FILE := GetTempDir + 'Notepad_FROM_RES.EXE';

end;

 

Delphi - .....................................

 

neoturk: ...Include a exe-file in your application and execute it ?...

1.

Start notepad and create a .rc-file that looks like this:

Starte Notepad und erstelle ein .rc-file, das etwa so aussieht:

 

TESTFILE EXEFILE C:WindowsNotepad.exe

 

(Make sure that the Path to your Exe-File is correct!)

(Stelle sicher, dass der Pfad zur Exe-Datei korrekt ist!)

 

2.

Save it as myres.rc

Speichere es als myres.rc

 

3.

Compile the file with brcc32.exe

(in your Delphi-bin directory) to get myres.res

Kompiliere die Datei mit brcc32.exe

(Im Delphi-bin Verzeichnis) um die Datei myres.res zu erhalten.

 

4.

Copy myres.res to your Project directory.

Kopiere myres.res in das entsprechende Projekt-Verzeichnis.

 

5.

In your unit write the following:

In der unit, schreibe etwa das folgende:

 

 

var

  Form1: TForm1;

  NOTEPAD_FILE: string;

 

implementation

 

{$R *.DFM}

{$R MYRES.RES}

 

function GetTempDir: string;

var

  Buffer: array[0..MAX_PATH] of Char;

begin

  GetTempPath(SizeOf(Buffer) - 1, Buffer);

  Result := StrPas(Buffer);

end;

 

// Extract the Resource

function ExtractRes(ResType, ResName, ResNewName: string): Boolean;

var

  Res: TResourceStream;

begin

  Result := False;

  Res := TResourceStream.Create(Hinstance, Resname, PChar(ResType));

  try

    Res.SavetoFile(ResNewName);

    Result := True;

  finally

    Res.Free;

  end;

end;

 

// Execute the file

procedure ShellExecute_AndWait(FileName: string);

var

  exInfo: TShellExecuteInfo;

  Ph: DWORD;

begin

  FillChar(exInfo, SizeOf(exInfo), 0);

  with exInfo do

  begin

    cbSize := SizeOf(exInfo);

    fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;

    Wnd := GetActiveWindow();

    ExInfo.lpVerb := 'open';

    lpFile := PChar(FileName);

    nShow := SW_SHOWNORMAL;

  end;

  if ShellExecuteEx(@exInfo) then

  begin

    Ph := exInfo.HProcess;

  end

  else

  begin

    ShowMessage(SysErrorMessage(GetLastError));

    Exit;

  end;

  while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do

    Application.ProcessMessages;

  CloseHandle(Ph);

end;

 

// To Test it

procedure TForm1.Button1Click(Sender: TObject);

begin

  if ExtractRes('EXEFILE', 'TESTFILE', NOTEPAD_FILE) then

    if FileExists(NOTEPAD_FILE) then

    begin

      ShellExecute_AndWait(NOTEPAD_FILE);

      ShowMessage('Notepad finished!');

      DeleteFile(NOTEPAD_FILE);

    end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  NOTEPAD_FILE := GetTempDir + 'Notepad_FROM_RES.EXE';

end;

 

Delphi - .....................................

 

neoturk: ...Delete the own program after its finish ?...

procedure DeleteEXE;

 

  function GetTmpDir: string;

  var

    pc: PChar;

  begin

    pc := StrAlloc(MAX_PATH + 1);

    GetTempPath(MAX_PATH, pc);

    Result := string(pc);

    StrDispose(pc);

  end;

 

  function GetTmpFileName(ext: string): string;

  var

    pc: PChar;

  begin

    pc := StrAlloc(MAX_PATH + 1);

    GetTempFileName(PChar(GetTmpDir), 'uis', 0, pc);

    Result := string(pc);

    Result := ChangeFileExt(Result, ext);

    StrDispose(pc);

  end;

 

var

  batchfile: TStringList;

  batchname: string;

begin

  batchname := GetTmpFileName('.bat');

  FileSetAttr(ParamStr(0), 0);

  batchfile := TStringList.Create;

  with batchfile do

  begin

    try

      Add(':Label1');

      Add('del "' + ParamStr(0) + '"');

      Add('if Exist "' + ParamStr(0) + '" goto Label1');

      Add('rmdir "' + ExtractFilePath(ParamStr(0)) + '"');

      Add('del ' + batchname);

      SaveToFile(batchname);

      ChDir(GetTmpDir);

      ShowMessage('Uninstalling program...');

      WinExec(PChar(batchname), SW_HIDE);

    finally

      batchfile.Free;

    end;

    Halt;

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Delete the own program after its finish ?...

procedure DeleteEXE;

 

  function GetTmpDir: string;

  var

    pc: PChar;

  begin

    pc := StrAlloc(MAX_PATH + 1);

    GetTempPath(MAX_PATH, pc);

    Result := string(pc);

    StrDispose(pc);

  end;

 

  function GetTmpFileName(ext: string): string;

  var

    pc: PChar;

  begin

    pc := StrAlloc(MAX_PATH + 1);

    GetTempFileName(PChar(GetTmpDir), 'uis', 0, pc);

    Result := string(pc);

    Result := ChangeFileExt(Result, ext);

    StrDispose(pc);

  end;

 

var

  batchfile: TStringList;

  batchname: string;

begin

  batchname := GetTmpFileName('.bat');

  FileSetAttr(ParamStr(0), 0);

  batchfile := TStringList.Create;

  with batchfile do

  begin

    try

      Add(':Label1');

      Add('del "' + ParamStr(0) + '"');

      Add('if Exist "' + ParamStr(0) + '" goto Label1');

      Add('rmdir "' + ExtractFilePath(ParamStr(0)) + '"');

      Add('del ' + batchname);

      SaveToFile(batchname);

      ChDir(GetTmpDir);

      ShowMessage('Uninstalling program...');

      WinExec(PChar(batchname), SW_HIDE);

    finally

      batchfile.Free;

    end;

    Halt;

  end;

end;

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol