begin
ShowMessage(ExtractFileDir(Application.Exename));
// ie: c:\\temp
ShowMessage(ExtractFilePath(Application.Exename));
// ie: c:\\temp\\
end;
相同点: 如果执行文件在根目录下(如:C:\\SAMPLE.EXE)的话, 两者的传回值相同, 且最后一个字符都是“/”。
使用GetFileVersionInfo 得到版本信息的例子
Samples Using GetFileVersionInfo?
回答1:
procedure GetBuildInfo(var V1, V2, V3, V4: Word);
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, \'\\\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
V1 := dwFileVersionMS shr 16;
V2 := dwFileVersionMS and $FFFF;
V3 := dwFileVersionLS shr 16;
V4 := dwFileVersionLS and $FFFF;
end;
FreeMem(VerInfo, VerInfoSize);
end;
------------------------------------------
回答2
If you want a component, check out TVersionInfoResource at
delphi/\">http://www.pobox.com/~bstowers/delphi/ in the My Stuff section. D1/D2/D3/C++B
compatible, freeware with full source code and a small demo.
And you can see the delphi/\">http://www.aye.net/~bstowers/delphi/
另一个component VersionInfo.zip
防止程序运行多个例程?
More than one instance of program?
回答
This is copied direct from my *.dpr file. You can work it for your own
use.
var
hMutex : Thandle;
WaitResult : word;
BroadcastList : DWORD;
begin
MessageID := RegisterWindowMessage(\'Check For Choice Previous Inst\');
// register a message to use later on
hMutex := createMutex(nil,false,pchar(\'App_Choice\')); // grab a mutex
handle
WaitResult := WaitForSingleObject(hMutex,10); // wait to see
if we can have exclusive use of the mutex
if ( waitResult = WAIT_TIMEOUT ) then // if we can\'t then broadcast
the message to make the owner of the mutex respond
{ request that the running application takes focus }
begin
BroadcastList := BSM_APPLICATIONS;
BroadcastSystemMessage(
BSF_POSTMESSAGE,@BroadcastList,MessageID,0,0); file://32 bit - broadcast the
message to all apps - only a prev inst will hear it.
end
else
begin
{ do the normal stuff}
Application.Title := \'Choice Organics Purchase & Sales System\';
Application.CreateForm(TMainForm, MainForm);
Application.Run;
ReleaseMutex(hMutex); // release the mutex as a politeness
end;
CloseHandle(hMutex); // close the mutex handle
end.
This goes in the MainForm
procedure Tmainform.OnAppMessage(var Msg : TMsg ; Var Handled : Boolean);
begin
{ If it\'s the special message then focus on this window}
if Msg.Message = MessageID then // if we get the broadcast message from an
another instance of this app that is trying to start up
begin
show;
WindowState := wsMaximized;
BringToFront;
SetFocus;
Handled := true;
end;
end;
file://And this goes in the TMainForm.FormCreate ;-
Application.OnMessage:= OnAppMessage;
4.得到Win 95 的计算机名字?
问 How can I learn Windows\'95 Machine Name?
答function ComputerName : String;
var
CNameBuffer : PChar;
fl_loaded : Boolean;
CLen : ^DWord;
begin
GetMem(CNameBuffer,255);
New(CLen);
CLen^:= 255;
fl_loaded := GetComputerName(CNameBuffer,CLen^);
if fl_loaded then
ComputerName := StrPas(CNameBuffer)
else
ComputerName := \'Unkown\';
FreeMem(CNameBuffer,255);
Dispose(CLen);
end;
7. 停止一个线程?
问 Stop A Thread?
回答
You can Terminate your thread in two ways:
1) Assign ThreadDone to OnTerminate when you create it.
In the Execute method, exit when the terminated property is True.
At the point where you want to stop, issue the Terminate method.
2) Just call the Suspend method.
After one of these steps you may free the thread.
I hope the following snippets will help.
// -------------------------------------------------------------- //
interface
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, \'\\\', Pointer(VerValue), VerValueSize);
with VerValue^ do
责任编辑:小草