Search results for 'Delphi'. 123 post(s) found.
- 2009/09/09 Is there directory selection VCL component in Delphi ?
- 2009/09/09 How to launch application ?
- 2009/09/09 How to print external document ?
- 2009/09/03 Delphi API to get windows temporary directory
- 2009/09/03 Delphi API to get the current working directory
- 2009/09/03 How to resize PNG file in Delphi ?
- 2009/08/22 Get the length of arrays and a string
- 2009/08/22 Delphi Pointer Types
- 2009/08/21 How to read/wrtie INI file in Delphi ?
- 2009/08/19 How to get file created time, modified time, and last accessed time ?
Delphi provides class for thread application as TThread.
Following is the simple example for thread application.
type
TForm1 = class(TForm)
Memo1: TMemo;
GroupBox1: TGroupBox;
seTimeToWork: TSpinEdit;
Label1: TLabel;
btnCreate: TButton;
btnTerminate: TButton;
procedure FormShow(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
procedure btnTerminateClick(Sender: TObject);
private
FThread:TThread;
procedure EnableButtons;
procedure OnTerminate(Sender:TObject);
end;
TMyThread=class(TThread)
private
FTimeToWork:integer;
protected
procedure Execute;override;
public
constructor Create(TimeToWork:integer);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// TMyThread
constructor TMyThread.Create(TimeToWork: integer);
begin
FTimeToWork:=TimeToWork;
inherited Create(True);
end;
procedure TMyThread.Execute;
var
T:Integer;
begin
t:=FTimeToWork;
Form1.Memo1.Lines.Add('Begin execution');
while not Terminated and (t>0) do
begin
Form1.Memo1.Lines.Add(format('Remaining %5.2f%%',[t/FTimeToWork*100]));
Sleep(500);
dec(t,500);
end;
if Terminated then
Form1.Memo1.Lines.Add('Terminated by user');
Form1.Memo1.Lines.Add('Finish execution');
end;
// TForm1
procedure TForm1.EnableButtons;
begin
btnCreate.Enabled:=not Assigned(FThread);
btnTerminate.Enabled:= Assigned(FThread);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
EnableButtons;
end;
procedure TForm1.btnCreateClick(Sender: TObject);
begin
FThread:=TMyThread.Create(seTimeToWork.Value);
FThread.OnTerminate:=OnTerminate;
EnableButtons;
FThread.Resume;
end;
procedure TForm1.btnTerminateClick(Sender: TObject);
begin
FThread.Terminate;
end;
procedure TForm1.OnTerminate(Sender: TObject);
begin
FThread:=nil;
EnableButtons;
end;
end.
TForm1 = class(TForm)
Memo1: TMemo;
GroupBox1: TGroupBox;
seTimeToWork: TSpinEdit;
Label1: TLabel;
btnCreate: TButton;
btnTerminate: TButton;
procedure FormShow(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
procedure btnTerminateClick(Sender: TObject);
private
FThread:TThread;
procedure EnableButtons;
procedure OnTerminate(Sender:TObject);
end;
TMyThread=class(TThread)
private
FTimeToWork:integer;
protected
procedure Execute;override;
public
constructor Create(TimeToWork:integer);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// TMyThread
constructor TMyThread.Create(TimeToWork: integer);
begin
FTimeToWork:=TimeToWork;
inherited Create(True);
end;
procedure TMyThread.Execute;
var
T:Integer;
begin
t:=FTimeToWork;
Form1.Memo1.Lines.Add('Begin execution');
while not Terminated and (t>0) do
begin
Form1.Memo1.Lines.Add(format('Remaining %5.2f%%',[t/FTimeToWork*100]));
Sleep(500);
dec(t,500);
end;
if Terminated then
Form1.Memo1.Lines.Add('Terminated by user');
Form1.Memo1.Lines.Add('Finish execution');
end;
// TForm1
procedure TForm1.EnableButtons;
begin
btnCreate.Enabled:=not Assigned(FThread);
btnTerminate.Enabled:= Assigned(FThread);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
EnableButtons;
end;
procedure TForm1.btnCreateClick(Sender: TObject);
begin
FThread:=TMyThread.Create(seTimeToWork.Value);
FThread.OnTerminate:=OnTerminate;
EnableButtons;
FThread.Resume;
end;
procedure TForm1.btnTerminateClick(Sender: TObject);
begin
FThread.Terminate;
end;
procedure TForm1.OnTerminate(Sender: TObject);
begin
FThread:=nil;
EnableButtons;
end;
end.
Another posts included in "Delphi"
| Is there directory selection VCL component in Delphi ? (0) | 2009/09/09 |
| How to launch application ? (0) | 2009/09/09 |
| How to print external document ? (0) | 2009/09/09 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
Trackback : Cannot send a trackbact to this post.
There are FileOpenDialog and FileSaveDialog components on Delphi VCL.
Sometimes you may need Directory Selection dialog, but no components are found on VCL.
Do you know Delphi provides the solution as SelectDirectory().
Here are two examples for Directory Selection.
Following shows directory structure under d:\delphi
procedure TForm1.Button1Click(Sender: TObject);
var
DirSelected: string;
begin
if SelectDirectory('Select a folder:', 'D:\Delphi', DirSelected) then
ShowMessage('You selected ' + DirSelected)
else
ShowMessage('You did not select a folder');
end;
var
DirSelected: string;
begin
if SelectDirectory('Select a folder:', 'D:\Delphi', DirSelected) then
ShowMessage('You selected ' + DirSelected)
else
ShowMessage('You did not select a folder');
end;
Following shows driver names and files as well as directory structure.
procedure TForm1.Button2Click(Sender: TObject);
var
Dir: string;
begin
Dir := 'D:\Delphi';
if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
ShowMessage('You selected ' + Dir)
else
ShowMessage('You did not select a folder');
end;
var
Dir: string;
begin
Dir := 'D:\Delphi';
if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
ShowMessage('You selected ' + Dir)
else
ShowMessage('You did not select a folder');
end;
Another posts included in "Delphi"
| Thread Application Implementation in TThread (0) | 2010/04/14 |
| How to launch application ? (0) | 2009/09/09 |
| How to print external document ? (0) | 2009/09/09 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
| How to resize PNG file in Delphi ? (0) | 2009/09/03 |
Trackback : Cannot send a trackbact to this post.
You can launch application on windows by ShellExecute function. Following is the simple example to launch application.
In case of running DOS command application such as batch file and you want not to display user, put SW_HIDE in the function option as follow
ShellExecute(Handle, 'open', PChar('c:\test\kurapa_backup.bat'), nil, nil, SW_HIDE);
Another posts included in "Delphi"
| Is there directory selection VCL component in Delphi ? (0) | 2009/09/09 |
| Thread Application Implementation in TThread (0) | 2010/04/14 |
| How to print external document ? (0) | 2009/09/09 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
| How to resize PNG file in Delphi ? (0) | 2009/09/03 |
| Get the length of arrays and a string (0) | 2009/08/22 |
Trackback : Cannot send a trackbact to this post.
Without complex programming, you can Print document by ShellExecute function.
Another posts included in "Delphi"
| How to launch application ? (0) | 2009/09/09 |
| Is there directory selection VCL component in Delphi ? (0) | 2009/09/09 |
| Thread Application Implementation in TThread (0) | 2010/04/14 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
| How to resize PNG file in Delphi ? (0) | 2009/09/03 |
| Get the length of arrays and a string (0) | 2009/08/22 |
| Delphi Pointer Types (0) | 2009/08/22 |
Trackback : Cannot send a trackbact to this post.
When you need to access windows temp directory, you can get from environment variables.
Following is the example to Get Temporary Directory.
var
m_tempdir: string
.
.
.
m_tempdir := GetEnvironmentVariable('TEMP');
m_tempdir: string
.
.
.
m_tempdir := GetEnvironmentVariable('TEMP');
Another posts included in "Delphi"
| How to print external document ? (0) | 2009/09/09 |
| How to launch application ? (0) | 2009/09/09 |
| Is there directory selection VCL component in Delphi ? (0) | 2009/09/09 |
| Delphi API to get the current working directory (0) | 2009/09/03 |
| How to resize PNG file in Delphi ? (0) | 2009/09/03 |
| Get the length of arrays and a string (0) | 2009/08/22 |
| Delphi Pointer Types (0) | 2009/08/22 |
| How to read/wrtie INI file in Delphi ? (0) | 2009/08/21 |
Prev


Rss Feed