还没有检查的. 请注意
//片段一:
procedure TForm1.flam(fil :AnsiString );
var
AnsiString argv,sourcepath,destpath;
int i;
Stream: TFILEStream;
curpos, length: longInt;
asd: TBar;
t: TTrad;
begin
for i:= Length(saveedit.Text)do
wnto 1do
if saveedit.Text = '//' then
break;
destpath := Copy(saveedit.Text, 1, i);
if (chdir(destpath)<>-1) then
begin
for i= Length(fil)do
wnto 1do
begin
if (fil = '//') then
break;
end;
sourcepath := Copy(fil, 1,i);
SetCurrentDir(Pchar(sourcepath));
filename := Copy(fil, Length(fil)-2, Length(fil));
argv := 'notepad.exe'+fil;
stream = TFileStream.Create(open.FileName, fmOpenRead);
with Streamdo
if (Size > 0) then
begin
bar.Max= Size div 100000;
hobbo :=true;
asd := TBar.Create(save.FileName);
end
else
Label1.Caption := open.FileName;
t = TTrad.Create(argv);
t.OnTerminate = ThreadDone;
end
else
ShowMessage('Can'''t find folder '+destpath);
end;
//片段二(thread.cpp单元):
uses .........
{include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "thread.h"
#include <assert.h>
}//---------------------------------------------------------------------
//* The Execute method is called when the thread starts */
// INTERFACE HERE
// IMPLEMENTS
constructor TSortThread.Create(AnsiString a);
begin
create(false);
argv:=a ;
end;
procedure TSortThread.Execute;
begin
readinfo();
end;
constructor TTrad.Create(AnsiString a);
begin
Inherited;
end;
constructor TBar.Create(AnsiString a);
begin
Inherited;
end;
function IsWindowsNT: Boolean
var
osv OSVERSIONINFO ;
begin
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
Result := (osv.dwPlatformId = VER_PLATFORM_WIN32_NT);
end;
procedure TTrad.readinfo;//关键段,特别要翻译到Delphi
var
///-todo
FBreak Integer;
TempFile: string;
sd SECURITY_DESCRIPTOR ;
sa SECURITY_ATTRIBUTES;
lpsa LPSECURITY_ATTRIBUTES = NULL;
hReadPipe HANDLE ;
hWritePipe HANDLE ;
si STARTUPINFO;
pi PROCESS_INFORMATION ;
BytesRead DWORD ;
//unsigned long
dest array[0..4000] of char ;
RdLoopDone boolean = false;
RawPath String;
begin
Application.ProcessMessages;
// If NTdo
security stuff
if (IsWindowsNT) then
begin
InitializeSecurityDescriptor(sd,
SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(sd, true, NULL, false);
sa.nLength := sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle := true;
sa.lpSecurityDescriptor := sd^;
lpsa := sa^;
end;
CreatePipe(hReadPipe,
hWritePipe,
lpsa,
2500000);
FillChar(&si, sizeof(STARTUPINFO), 0);
si.cb := sizeof(STARTUPINFO);
si.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
si.wShowWindow := SW_HIDE;
si.hStdOutput := hWritePipe;
si.hStdError := hWritePipe;
assert(hWritePipe);
Application.ProcessMessages;
assert(CreateProcess(NULL,
Pchar(argv),
NULL,//security
NULL,// security
TRUE,//inherits handles
0,
0,
0,
&si,
&pi));
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, 9000000000);
assert(hReadPipe);
Form1.ResultsRE.Lines.Clear();
while (not RdLoopDone)do
begin
FillChar(dest, 4000, 0);
assert(ReadFile(hReadPipe, &dest, sizeof(dest), &BytesRead, NULL));
Form1.ResultsRE.Lines.Add(String(dest));
if (BytesRead < 4000) then
RdLoopDone = true;
end;
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
CloseHandle(pi.hProcess);
Form1.ResultsRE.Perform(EM_SETSEL,0,0);
hobbo:=false;
end;
procedure TBar.readinfo;//关键段,特别要翻译到Delphi
var
stream: file;
curpos, length,lengthold : LongInt;;
tecken :AnsiString = '';
begin
Form1.Label1.Caption := '分析文件..请等待...'+tecken;
while(hobbo)do
begin
AssignFile(stream , argv);
length = FileSize(stream);
if(length > 0) then
begin
Form1.bar.Position :=length div 100000 ;
Form1.Label1.Caption :='生成文件...'+IntToStr(length div 1048576 )+ ' MB';
if(length =lengthold) then
Form1.Label1.Caption='分析文件..请等待...'+tecken;
end
else
Form1.Label1.Caption: = '分析文件..请等待...'+tecken;
if(tecken = '') then
//
tecken= ''//"";
//
else
tecken= '';//"";
//
CloseFile(stream);
lengthold:=length;
Sleep(300);
end;
end;