很久以前的代码,for d5-d7
作用是把保存在书库中的源代码转成delphi工程,参考一下吧
var i,j,Level,Count,ii:integer;
s,sourcePath:string;
ProjList,FileList
StringList;
stm1:TFileStream;
stm2:TMemoryStream;
sfmt:TStreamOriginalFormat;
begin
if FMemo<>nil then begin
SourcePath:=ExtractFilePath(projectName);
Result:=False;
if FTV.Selected=nil then exit;
// ParentID:=FTV.Selected.AbsoluteIndex;
Level:=FTV.Selected.Level;
if FileExists(ProjectName) then
if MessageDlg('文件已存在,覆盖吗?',
mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
exit;
if FMemo.Text='' then exit;
New(ProjList);
ProjList^:=TStringList.Create;
new(FileList);
FileList^:=TStringList.Create;
ProjList^.Text:=FMemo.Text;
for i:=0 to ProjList^.Count-1 do begin
if trim(ProjList^.Strings
)<>'//' then begin
break;
end;
end;
s:=UpperCase(copy(trim(ProjList^.Strings),1,7));
try
GetProjectFilesName(ProjList,FileList);
for i:=0 to Filelist^.count-1 do
begin
if ExtractFilePath(Filelist^.Strings)<>'' then
if not DirectoryExists(ExtractFilePath(Filelist^.Strings)) then
mkdir(ExtractFilePath(Filelist^.strings));
if pbar<>nil then
pbar.Position:=((i+1)*100 div FileList.Count);
application.ProcessMessages;
end;
if IsDelphiProjectFile(s) then begin
ProjList^.Text:=FMemo.Text;
ProjList^.SaveToFile(ProjectName);
i:=FTV.Selected.AbsoluteIndex+1;
// Count:=0;
while (i<FTV.Items.Count)and (level<FTV.Items.Level) do begin
i:=i+1;
end;
Count:=i;
i:=FTV.Selected.AbsoluteIndex+1;
ii:=i;
while (i<Count) and (level<FTV.Items.Level) do begin
s:='';
for j:=0 to Filelist^.Count-1 do
begin
FTV.Items[j].Selected:=True;
TVChange(FTV,FTV.Selected);
// application.ProcessMessages;
if pos(uppercase(copy(FTV.Items.Text,1,length(FTV.Items.Text)-4)),uppercase(Filelist^.Strings[j]))>0 then
begin
s:=ExtractFilePath(Filelist^.Strings[j]);
break;
end;
end;
FTV.Items.Selected:=True;
TVChange(FTV,FTV.Selected);
// Application.ProcessMessages;
if pos('.PAS',uppercase(FTV.Items.Text))>0 then begin
ProjList^.Text:=FMemo.Text;
ProjList^.SaveToFile(sourcePath+s+FTV.Items.Text);
end else if pos('.DFM',uppercase(FTV.Items.Text))>0 then begin
ProjList^.Text:=FMemo.Text;
stm2:=TMemoryStream.Create;
ProjList^.SaveToStream(stm2);
stm1:=TFileStream.Create(SourcePath+s+FTV.Selected.Text,fmCreate);
try
stm2.Position:=0;
stm1.Position:=0;
sfmt:=TestStreamFormat(stm2);
ObjectTextToResource(stm2,stm1,sfmt);
finally
stm1.Destroy;
stm2.Destroy;
end;
end;
if Pbar<>nil then
pbar.Position:=(i-ii+1)*100 div (Count-ii);
Application.ProcessMessages;
i:=i+1;
end;
showMessage('工程文件导出完毕');
Result:=True;
end;
finally
ProjList^.Destroy;
FIleList^.Destroy;
dispose(ProjList);
dispose(FileList);
pbar.Position:=0;
if PBar<>nil then
PBar.Position:=0;
end;
end else
Result:=False;
end;