📄 mainform.pas
字号:
function GetUniqueUnitName:string;
function GetUniqueFormName:string;
procedure ProxyFormShow(Sender: TObject);
function UniqueName(Comp:TComponent):string;
function TryName(const Test:string;Comp:TComponent):Boolean;
function GetUnitName(const FormName:string):string;
procedure SaveHistory(const Project:string);
procedure OpenHistory;
procedure OpenHistoryFile(Sender: TObject);
procedure ExecuteTool(Sender: TObject);
procedure UpdateControl;
function GetCursorWord:string;
function SearchingText(SearchStr:string;Options:TYB_SearchType):Boolean;
procedure ReplacingText(FindText,ReplaceText:string;Options:TYB_SearchType);
procedure ReadClass;
public
{ Public declarations }
SelectUnit: string; // 泅犁 累诀窍绊 乐绰 蜡聪飘狼 捞抚
SelectedComponent:TComponent;
ActiveForm:TForm; // 泅犁 累诀窍绊 乐绰 汽
// 积己茄 葛电 汽苞 蜡聪飘狼 沥焊甫 历厘窍扁 困茄 硅凯
procedure OpenFile(const FileName:string);
procedure SaveFile(const FileName:string);
function GetSelectComponent:TComponentClass;
function GetLinkForm:TForm;
procedure ToggleFormAndUnit;
procedure OpenTools;
property ShiftKeyed:Boolean read fShiftKeyed write fShiftKeyed;
end;
var
FMainForm: TFMainForm;
SearchOption:TYB_SearchType;
implementation
uses ObjectInspec, Proxy, About, Editor, uviewform, Uconst, UProject, utils,
UOptions, UProOption, ucreateform, ShellAPI,IniFiles,
URemoveUnit, UWindowList, UComponentList, Utools, ucompile, USearch,RichEdit,
UFindInFile, UReplace;
var
EndPos,OldLine,MatchPos:integer;
SearchText:string;
{$R *.DFM}
procedure TFMainForm.FormCreate(Sender: TObject);
begin
// 橇肺璃飘 券版阑 檬扁拳茄促.
Left:=0;
Top:=0;
ToggleFormUnit:=False;
PageControl1.ActivePage:=TabStandard;
SourceList:= TStringList.Create;
ProjectInfo:=TProjectInfo.Create(self);
GetDir(0,TempDir);
if TempDir[Length(TempDir)]<>'\' then TempDir:=TempDir+'\';
FilePath:=ExtractFilePath(Application.ExeName);
IniFile:=TIniFile.Create(FilePath+IniName);
Complier:=IniFile.ReadString('SYSTEM','COMPLIER','');
Desktop:=IniFile.ReadString('SYSTEM','DESKTOP','');
OpenHistory;
OpenTools;
end;
procedure TFMainForm.FileExitItemClick(Sender: TObject);
begin
Close;
end;
procedure TFMainForm.FormShow(Sender: TObject);
var
List: TStringList;
begin
ObjectInspector.Show;
EditorForm.Show;
//ProxyForm.Show;
CreateForm(GetUniqueFormName,GetUniqueUnitName);
// 货肺款 橇肺璃飘狼 叼弃飘 家胶 累己
ProjectInfo.ProjectSource:=CreateDefaultProject(ProjectInfo.ProjectSource);
// 叼弃飘 蜡聪飘狼 内靛甫 累己茄促.
List:=TStringList.Create;
List:=CreateDefaultUnit(List,'Unit1','Form1');
EditorForm.RichEdit1.Lines.Assign(List);
// List.SaveToFile(TempDir+'Unit1.pas');
List.Free;
NewProject;
ActiveRichEdit:=EditorForm.RichEdit1;
end;
procedure TFMainForm.HelpAboutItemClick(Sender: TObject);
begin
CreateShowModal(TAboutBox);
end;
procedure TFMainForm.sbButtonClick(Sender: TObject);
var
st:Integer;
begin
SelectedComponentIndex:=(Sender as TSpeedButton).Tag;
st:=GetKeyState(VK_SHIFT);
if SelectedComponentIndex = scNoComponent then ShiftKeyed:= False
else if st < 0 then ShiftKeyed:= True
else ShiftKeyed:= False;
end;
{炼惑栏肺何磐 拌铰罐绊 林绢柳 努贰胶 捞抚阑 ClassName捞扼 窍绰 橇废矫 按眉甫 父电促.}
function TFMainForm.CreateProxy(Ancestor:TFormClass;const ClassName:string):TObject;
begin
Result:=Ancestor.Create(nil);
Proxies.CreateSubClass(Result,ClassName,Ancestor);
end;
procedure TFMainForm.sbOpenFileClick(Sender: TObject);
begin
OpenDialog1.Title:='Open';
OpenDialog1.Filter := 'Delphi Files(*.pas;*.dpr)|*.pas;*.dpr'+
'|Delphi Project(*.dpr)|*.dpr'+
'|Delphi Unit(*.pas)|*.pas'+
'|Delphi Form(*.dfm)|*.dfm'+
'|Text File(*.txt)|*.txt'+
'|All Files (*.*)|*.*';
if OpenDialog1.Execute then OpenFile(OpenDialog1.FileName);
end;
procedure TFMainForm.sbFormsClick(Sender: TObject);
var
FormName:string;
begin
// 橇肺璃飘俊 器窃等 汽狼 格废阑 焊咯霖促.
with TViewForm.Create(self) do begin
Caption:='Form List';
FileList.Items.Assign(ProjectInfo.FormItems);
if ShowModal<>mrCancel then begin
FormName:=GetUnitName(FileName.Text);
OpenFile(ProjectInfo.ProjectPath+FormName+'.pas');
end;
Free;
end;
end;
procedure TFMainForm.sbUnitsClick(Sender: TObject);
begin
// 橇肺璃飘俊 器窃等 蜡聪飘狼 格废阑 焊咯霖促.
with TViewForm.Create(self) do begin
Caption:='Unit List';
FileList.Items.Assign(ProjectInfo.UnitItems);
if ShowModal<>mrCancel then
OpenFile(ProjectInfo.ProjectPath+FileName.Text+'.pas');
Free;
end;
end;
procedure TFMainForm.OpenFile(const FileName:string);
var
Input,Output:TMemoryStream;
begin
if not FileExists(FileName) then Exit;
if ExtractFileExt(FileName)='.dpr' then begin
ProjectInfo.ProjectName:=FileName;
Projectinfo.ProjectPath:=ExtractFilePath(FileName);
// 橇肺璃飘 家胶甫 焊绰 版快甫 措厚窍咯
if ProjectInfo.ProjectState<>psNew then CreateSheet(FileName);
end
// 汽颇老(dfm )牢 版快 汽阑 咆胶飘肺 佬绰促.
else if ExtractFileExt(FileName)='.dfm' then begin
Input:=TMemoryStream.Create;
Input.LoadFromFile(FileName);
Output:=TMemoryStream.Create;
ObjectResourceToText(Input,Output);
Output.SaveToFile(ProjectInfo.ProjectPath+TempFile);
Input.Free;
// Output.Free;
CreateSheet(ExtractFileName(FileName));
OpenForm(FileName);
end
else if ExtractFileExt(FileName)='.pas' then begin
CreateSheet(ExtractFileName(FileName));
OpenForm(Copy(FileName,1,Length(FileName)-3)+'dfm');
end
else begin
CreateSheet(ExtractFileName(FileName));
end;
SaveHistory(FileName);
end;
procedure TFMainForm.ViewPrjSourceItemClick(Sender: TObject);
begin
if ProjectInfo.ProjectState=psNew then CreateSheet('Project1') // 货 橇肺璃飘甫 父靛绰 版快
else OpenFile(ProjectInfo.ProjectName);
end;
// 扁粮狼 橇肺璃飘 颇老阑 阂矾柯促.
procedure TFMainForm.sbOpenProjectClick(Sender: TObject);
begin
OpenDialog1.Title:='Open Project';
// OpenDialog1.Filter := 'Project Files (*.dpr)|*.dpr|All Files (*.*)|*.*';
OpenDialog1.FilterIndex:=2;
if OpenDialog1.Execute then OpenProject(OpenDialog1.FileName);
end;
procedure TFMainForm.ViewPrjMgrItemClick(Sender: TObject);
begin
with TProjectManager.Create(self) do begin
GetProjectInfo;
Show;
end;
end;
procedure TFMainForm.ProjectCompileItemClick(Sender: TObject);
begin
CompileAndInformation('/M');
end;
procedure TFMainForm.ProjectBuildItemClick(Sender: TObject);
begin
CompileAndInformation('/B');
end;
// 橇肺技胶甫 积己窍绊, 橇肺技胶啊 场朝 锭鳖瘤 措扁茄促.
function ExecuteProcess(const ProcessName:string):Boolean;
var
StartInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
dwExitCode:Integer;
S1,S2:string;
begin
Result:=True;
dwExitCode:= STILL_ACTIVE;
FillChar(StartInfo, SizeOf(TStartupInfo), #0);
FillChar(ProcessInfo, SizeOf(TProcessInformation), #0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.dwFlags := STARTF_USESHOWWINDOW;
StartInfo.wShowWindow:= SW_HIDE;
CreateProcess( nil,PChar(ProcessName),
nil, nil, false, DETACHED_PROCESS + HIGH_PRIORITY_CLASS,
nil, nil, StartInfo, ProcessInfo );
WaitForInputIdle(GetCurrentProcess(), INFINITE);
if ProcessInfo.hProcess <> 0 then begin
while (dwExitCode = STILL_ACTIVE) do begin
WaitForSingleObject(ProcessInfo.hProcess,1000);
GetExitCodeProcess(ProcessInfo.hProcess, dwExitCode);
end;
end;
end;
// 橇肺璃飘甫 哪颇老茄促. (Option篮 哪颇老 可记: /B 肚绰 /M)
function Compile(const Option:string):Boolean;
var
S1,S2:String;
List:TStringList;
begin
Result:=True;
if not FileExists(Complier+'DCC32.exe') then begin
ShowMessage('Cannot find Delphi complier!');
Result:= False;
Exit;
end;
Screen.Cursor:= crHourGlass;
if not FileExists(FilePath+'execute.bat') then begin
SetLength(S1,Length(Complier+'DCC32.exe'));
List:= TStringList.Create;
GetShortPathName(PChar(Complier+'DCC32.exe'),PChar(S1),Length(S1));
List.Add(Copy(S1,1,Length(S1))+' %1 %2 >'+CompileText);
// List.Add('Pause');
List.SaveToFile(FilePath+'execute.bat');
List.Free;
end;
SetLength(S2,Length(ProjectInfo.ProjectName));
GetShortPathName(PChar(ProjectInfo.ProjectName),PChar(S2),Length(S2));
ExecuteProcess(FilePath+'execute.bat '+ Option+' '+S2);
Screen.Cursor:= crDefault;
end;
// 橇肺璃飘甫 哪颇老窍绊, 哪颇老 搬苞甫 焊咯霖促.
function TFMainForm.CompileAndInformation(const Option:string):Boolean;
begin
Compile(Option);
CreateShowModal(TCompile);
end;
// 橇肺璃飘甫 哪颇老窍绊, 角青茄促.
procedure TFMainForm.RunRunItemClick(Sender: TObject);
var
ret:integer;
ExeName:string;
begin
if Compile('/M') then begin
ExeName:=Copy(ProjectInfo.ProjectName,1,Length(ProjectInfo.ProjectName)-3)+'exe';
ret:=WinExec(PChar(ExeName),SW_SHOWNORMAL);
if ret<31 then ShowMessage('Cannot Execute ' + ExeName+'!');
end;
end;
procedure TFMainForm.SaveProxyForm;
var
OutPut: TMemoryStream;
ResName:string;
begin
// if ProxyForm.GrabHandles<>nil then ProxyForm.GrabHandles.Free;
ResName:=ProjectInfo.ProjectPath+'unit1.dfm';
Output:=TMemoryStream.Create;
OutPut.WriteComponentRes(ResName,ProxyForm);
Output.SaveToFile(ResName);
Output.Free;
end;
// Form 颇老阑 历厘茄促.
procedure TFMainForm.SaveForm(Form:TForm;FormName:string);
var
Output: TMemoryStream;
ResName:string;
I:Integer;
begin
Form.OnActivate:= nil;
Form.OnCreate:= nil;
Form.OnDestroy:= nil;
Form.OnMouseDown:= nil;
Form.OnMouseMove:= nil;
Form.OnMouseUp:= nil;
Form.OnResize:= nil;
Form.OnPaint:= nil;
for I:=Form.ComponentCount-1 downto 0 do begin
if Form.Components[I] is TGrabHandle then Form.Components[I].Free;
//else if Form.Components[I] is TWrapperControl then Form.Components[I].Free;
end;
ResName:=FormName;
Output:=TMemoryStream.Create;
OutPut.WriteComponentRes(ResName,Form);
Output.SaveToFile(ResName);
Output.Free;
// Form.OnActivate:= ProxyForm.FormActivate;
// Form.OnDestroy:= ProxyForm.FormDestroy;
// Form.OnMouseDown:= ProxyForm.FormMouseDown;
// Form.OnMouseMove:= ProxyForm.FormMouseMove;
// Form.OnMouseUp:= ProxyForm.FormMouseUp;
// Form.OnPaint:= ProxyForm.FormPaint;
end;
// 橇废矫 汽阑 积己茄促.
function TFMainForm.CreateForm(const FormName,UnitName:string):TForm;
begin
Result:=CreateProxy(TProxyForm,'T'+GetNetFileName(FormName)) as TForm;
with Result do begin
BorderStyle:=bsSizeable;
Caption:=GetNetFileName(FormName);
Name:=GetNetFileName(FormName);
TProxyForm(Result).FileName:= UnitName;
// Height:=348;
// Width:=536;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -