MG: bugfixes + starting programs

git-svn-id: trunk@276 -
This commit is contained in:
lazarus 2001-05-29 08:16:27 +00:00
parent 36ba602a24
commit 9068ebd544
6 changed files with 89 additions and 56 deletions

View File

@ -926,19 +926,16 @@ var Find,Atom:string;
FindPosition,FindAtomStart,SemicolonPos:integer; FindPosition,FindAtomStart,SemicolonPos:integer;
begin begin
Result:=false; Result:=false;
if AddCode='' then begin if AddCode='' then exit;
Result:=true;
exit;
end;
if Source='' then exit; if Source='' then exit;
// search "LazarusResources.Add('<ResourceName>'," // search the "LazarusResources.Add('<ResourceName>'," in AddCode
FindPosition:=1; FindPosition:=1;
repeat repeat
Atom:=ReadNextPascalAtom(Source,FindPosition,FindAtomStart); Atom:=ReadNextPascalAtom(AddCode,FindPosition,FindAtomStart);
until (Atom='') or (Atom=','); until (Atom='') or (Atom=',');
if Atom='' then exit; if Atom='' then exit;
// search the resource start in code // search the resource start in code
Find:=copy(AddCode,1,FindPosition); Find:=copy(AddCode,1,FindPosition-1);
Position:=SearchCodeInSource(Source,Find,1,EndPosition,false); Position:=SearchCodeInSource(Source,Find,1,EndPosition,false);
if Position<1 then exit; if Position<1 then exit;
// search resource end in code // search resource end in code

View File

@ -32,7 +32,7 @@ uses
Classes, SysUtils, Forms, Controls, CompilerOptions, Project, Process; Classes, SysUtils, Forms, Controls, CompilerOptions, Project, Process;
type type
TOnOutputString = procedure (Value: String) of Object; TOnOutputString = procedure (const Value: String) of Object;
TErrorType = (etNone, etHint, etWarning, etError, etFatal); TErrorType = (etNone, etHint, etWarning, etError, etFatal);
TOnCmdLineCreate = procedure(var CmdLine: string; var Abort:boolean) TOnCmdLineCreate = procedure(var CmdLine: string; var Abort:boolean)
of object; of object;
@ -46,7 +46,7 @@ type
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
function Compile(AProject: TProject): TModalResult; function Compile(AProject: TProject): TModalResult;
function GetSourcePosition(Line: string; var Filename:string; function GetSourcePosition(const Line: string; var Filename:string;
var CaretXY: TPoint; var MsgType: TErrorType): boolean; var CaretXY: TPoint; var MsgType: TErrorType): boolean;
property OnOutputString : TOnOutputString property OnOutputString : TOnOutputString
read FOnOutputString write FOnOutputString; read FOnOutputString write FOnOutputString;
@ -63,7 +63,7 @@ const
var var
Compiler1 : TCompiler; Compiler1 : TCompiler;
function ErrorTypeNameToType(Name:string): TErrorType; function ErrorTypeNameToType(const Name:string): TErrorType;
implementation implementation
@ -74,11 +74,12 @@ uses linux;
{$ENDIF linux} {$ENDIF linux}
function ErrorTypeNameToType(Name:string): TErrorType; function ErrorTypeNameToType(const Name:string): TErrorType;
var LowName: string;
begin begin
Name:=lowercase(Name); LowName:=lowercase(Name);
for Result:=Low(TErrorType) to High(TErrorType) do for Result:=Low(TErrorType) to High(TErrorType) do
if lowercase(ErrorTypeNames[Result])=Name then exit; if lowercase(ErrorTypeNames[Result])=LowName then exit;
Result:=etNone; Result:=etNone;
end; end;
@ -166,7 +167,7 @@ begin
end; end;
end; end;
// TProcess does not report, if a program can not be executed // TProcess does not report, if a program can not be executed
// to get good error messages consider the os // to get good error messages consider the OS
{$IFDEF linux} {$IFDEF linux}
if not Linux.Access(CmdLine,Linux.X_OK) then begin if not Linux.Access(CmdLine,Linux.X_OK) then begin
case LinuxError of case LinuxError of
@ -220,7 +221,8 @@ begin
if Buf[i] in [#10,#13] then begin if Buf[i] in [#10,#13] then begin
OutputLine:=OutputLine+copy(Buf,LineStart,i-LineStart); OutputLine:=OutputLine+copy(Buf,LineStart,i-LineStart);
ProcessOutputLine; ProcessOutputLine;
if (i<Count) and (Buf[i+1] in [#10,#13]) and (Buf[i]<>Buf[i+1]) then if (i<Count) and (Buf[i+1] in [#10,#13]) and (Buf[i]<>Buf[i+1])
then
inc(i); inc(i);
LineStart:=i+1; LineStart:=i+1;
end; end;
@ -250,14 +252,11 @@ end;
{-------------------------------------------------------------------------- {--------------------------------------------------------------------------
TCompiler GetSourcePosition TCompiler GetSourcePosition
---------------------------------------------------------------------------} ---------------------------------------------------------------------------}
function TCompiler.GetSourcePosition(Line: string; var Filename:string; function TCompiler.GetSourcePosition(const Line: string; var Filename:string;
var CaretXY: TPoint; var MsgType: TErrorType): boolean; var CaretXY: TPoint; var MsgType: TErrorType): boolean;
{This assumes the line will have the format { This assumes the line has one of the following formats
<filename>(123,45) <ErrorType>: <some text> <filename>(123,45) <ErrorType>: <some text>
ToDo: parse format:
<filename>(456) <ErrorType>: <some text> in line (123) <filename>(456) <ErrorType>: <some text> in line (123)
} }
var StartPos, EndPos: integer; var StartPos, EndPos: integer;
begin begin
@ -312,6 +311,9 @@ end.
{ {
$Log$ $Log$
Revision 1.13 2001/05/29 08:16:26 lazarus
MG: bugfixes + starting programs
Revision 1.12 2001/04/04 12:20:34 lazarus Revision 1.12 2001/04/04 12:20:34 lazarus
MG: added add to/remove from project, small bugfixes MG: added add to/remove from project, small bugfixes

View File

@ -47,7 +47,7 @@ begin
BinMemStream.CopyFrom(BinFileStream,BinFileStream.Size); BinMemStream.CopyFrom(BinFileStream,BinFileStream.Size);
BinMemStream.Position:=0; BinMemStream.Position:=0;
BinExt:=uppercase(ExtractFileExt(BinFilename)); BinExt:=uppercase(ExtractFileExt(BinFilename));
if BinExt='.LFM' then begin if (BinExt='.LFM') or (BinExt='.DFM') then begin
ResourceType:='FORMDATA'; ResourceType:='FORMDATA';
ResourceName:=FindLFMClassName(BinMemStream); ResourceName:=FindLFMClassName(BinMemStream);
if ResourceName='' then begin if ResourceName='' then begin

View File

@ -233,6 +233,7 @@ type
function DoAddActiveUnitToProject: TModalResult; function DoAddActiveUnitToProject: TModalResult;
function DoRemoveFromProjectDialog: TModalResult; function DoRemoveFromProjectDialog: TModalResult;
function DoBuildProject: TModalResult; function DoBuildProject: TModalResult;
function DoRunProject: TModalResult;
function SomethingOfProjectIsModified: boolean; function SomethingOfProjectIsModified: boolean;
function DoCreateProjectForProgram(ProgramFilename, function DoCreateProjectForProgram(ProgramFilename,
ProgramSource: string): TModalResult; ProgramSource: string): TModalResult;
@ -688,8 +689,8 @@ begin
ViewUnitsSpeedBtn := CreateButton('ViewUnitsSpeedBtn' , 'btn_viewunits' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuViewUnitsClicked); ViewUnitsSpeedBtn := CreateButton('ViewUnitsSpeedBtn' , 'btn_viewunits' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuViewUnitsClicked);
ViewFormsSpeedBtn := CreateButton('ViewFormsSpeedBtn' , 'btn_viewforms' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuViewFormsClicked); ViewFormsSpeedBtn := CreateButton('ViewFormsSpeedBtn' , 'btn_viewforms' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuViewFormsClicked);
ToggleFormSpeedBtn := CreateButton('ToggleFormSpeedBtn' , 'btn_toggleform', 1, ButtonLeft, ButtonTop, [mfLeft], @mnuToggleFormUnitCLicked); ToggleFormSpeedBtn := CreateButton('ToggleFormSpeedBtn' , 'btn_toggleform', 1, ButtonLeft, ButtonTop, [mfLeft], @mnuToggleFormUnitCLicked);
NewFormSpeedBtn := CreateButton('NewFormSpeedBtn' , 'btn_newform' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuNewFormCLicked); NewFormSpeedBtn := CreateButton('NewFormSpeedBtn' , 'btn_newform' , 1, ButtonLeft, ButtonTop, [mfLeft], @mnuNewFormClicked);
RunSpeedButton := CreateButton('RunSpeedButton' , 'btn_run' , 2, ButtonLeft, ButtonTop, [mfLeft, mfTop], nil {@mnuRunClicked}); RunSpeedButton := CreateButton('RunSpeedButton' , 'btn_run' , 2, ButtonLeft, ButtonTop, [mfLeft, mfTop], @mnuRunProjectClicked);
// pnlSpeedButtons.Width := ButtonLeft; // pnlSpeedButtons.Width := ButtonLeft;
// pnlSpeedButtons.Height := ButtonTop; // pnlSpeedButtons.Height := ButtonTop;
@ -846,7 +847,7 @@ begin
itmSearchFind := TMenuItem.Create(nil); itmSearchFind := TMenuItem.Create(nil);
itmSearchFind.Name:='itmSearchFind'; itmSearchFind.Name:='itmSearchFind';
itmSearchFind.caption := 'Find'; itmSearchFind.Caption := 'Find';
mnuSearch.add(itmSearchFind); mnuSearch.add(itmSearchFind);
itmSearchFindAgain := TMenuItem.Create(nil); itmSearchFindAgain := TMenuItem.Create(nil);
@ -961,7 +962,6 @@ begin
itmProjectBuild.Name:='itmProjectBuild'; itmProjectBuild.Name:='itmProjectBuild';
itmProjectBuild.Caption := 'Build'; itmProjectBuild.Caption := 'Build';
itmProjectBuild.OnClick := @mnuBuildProjectClicked; itmProjectBuild.OnClick := @mnuBuildProjectClicked;
itmProjectBuild.Enabled := False;
mnuProject.Add(itmProjectBuild); mnuProject.Add(itmProjectBuild);
itmProjectRun := TMenuItem.Create(Self); itmProjectRun := TMenuItem.Create(Self);
@ -1253,6 +1253,12 @@ begin
Handled:=true; Handled:=true;
DoBuildProject; DoBuildProject;
end; end;
ecRun:
begin
Handled:=true;
if DoBuildProject<>mrOk then exit;
DoRunProject;
end;
end; end;
end; end;
@ -1450,31 +1456,8 @@ Begin
end; end;
Procedure TMainIDE.mnuRunProjectClicked(Sender : TObject); Procedure TMainIDE.mnuRunProjectClicked(Sender : TObject);
var
TheProcess : TProcess;
TheProgram : String;
begin begin
Assert(False, 'Trace:Run Project Clicked'); DoRunProject;
if SourceNotebook.Empty then Begin
Application.MessageBox('No units loaded. Load a program first!','Error',mb_OK);
Exit;
end;
TheProgram := ExtractFileName(SourceNotebook.ActiveUnitName);
//remove the extension
if pos('.',TheProgram) <> 0 then
delete(ThePRogram,pos('.',TheProgram),length(TheProgram));
if not FileExists(ExtractFilePath(SOurceNotebook.ActiveUnitName)+TheProgram) then Begin
TheProgram := 'No program called "'+TheProgram+'" found!';
Application.MessageBox(@TheProgram,'Error',MB_OK);
exit;
end;
TheProcess:=TProcess.Create(TheProgram,[poRunSuspended,poUsePipes,poNoConsole]);
TheProcess.Execute;
end; end;
procedure TMainIDE.mnuProjectCompilerSettingsClicked(Sender : TObject); procedure TMainIDE.mnuProjectCompilerSettingsClicked(Sender : TObject);
@ -2293,7 +2276,10 @@ writeln('TMainIDE.DoNewProject 1');
begin begin
// create a first form unit // create a first form unit
Project.CompilerOptions.OtherUnitFiles:= Project.CompilerOptions.OtherUnitFiles:=
'$(LazarusDir)'+OSDirSeparator+'lcl'+OSDirSeparator+'units'; '$(LazarusDir)'+OSDirSeparator+'lcl'+OSDirSeparator+'units'
+';'+
'$(LazarusDir)'+OSDirSeparator+'lcl'+OSDirSeparator+'units'
+OSDirSeparator+'gtk';
DoNewEditorUnit(nuForm); DoNewEditorUnit(nuForm);
end; end;
ptProgram,ptCustomProgram: ptProgram,ptCustomProgram:
@ -2760,6 +2746,51 @@ begin
end; end;
end; end;
function TMainIDE.DoRunProject: TModalResult;
// quick hack to start programs
// ToDo:
// -switch the IDE mode to running and free the process when program terminates
// -implement a better messages form for vast amount of output
// -target filename
// -command line parameters
// -connect program to debugger
var
TheProcess : TProcess;
ProgramFilename, Ext, AText : String;
begin
Result:=mrCancel;
writeln('[TMainIDE.DoRunProject] A');
if ToolStatus<>itNone then begin
Result:=mrAbort;
exit;
end;
if not (Project.ProjectType in [ptProgram, ptApplication, ptCustomProgram])
then exit;
Ext:=ExtractFileExt(Project.ProjectFile);
ProgramFilename := LowerCase(copy(Project.ProjectFile,1,
length(Project.ProjectFile)-length(Ext)));
if not FileExists(ProgramFilename) then begin
AText:='No program file "'+ProgramFilename+'" found!';
Application.MessageBox(PChar(AText),'File not found',MB_OK);
exit;
end;
try
TheProcess:=TProcess.Create(ProgramFilename,
[poRunSuspended,poUsePipes,poNoConsole]);
TheProcess.Execute;
except
on e: Exception do begin
AText:='Error running program "'+ProgramFilename+'": '+e.Message;
Application.MessageBox(PChar(AText),'Error',MB_OK);
end;
end;
Result:=mrOk;
writeln('[TMainIDE.DoRunProject] END');
end;
function TMainIDE.SomethingOfProjectIsModified: boolean; function TMainIDE.SomethingOfProjectIsModified: boolean;
begin begin
Result:=(Project<>nil) Result:=(Project<>nil)
@ -3358,6 +3389,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.98 2001/05/29 08:16:26 lazarus
MG: bugfixes + starting programs
Revision 1.97 2001/05/28 10:00:54 lazarus Revision 1.97 2001/05/28 10:00:54 lazarus
MG: removed unused code. fixed editor name bug. MG: removed unused code. fixed editor name bug.

View File

@ -37,7 +37,7 @@ type
Function GetMessage : String; Function GetMessage : String;
public public
constructor Create(AOwner : TComponent); override; constructor Create(AOwner : TComponent); override;
Procedure Add(Texts : String); Procedure Add(const Texts : String);
Procedure Clear; Procedure Clear;
Function GetSelectedLineIndex : Integer; Function GetSelectedLineIndex : Integer;
property Message : String read GetMessage; property Message : String read GetMessage;
@ -74,7 +74,7 @@ end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TMessagesView.Add } { TMessagesView.Add }
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
Procedure TMessagesView.Add(Texts : String); Procedure TMessagesView.Add(const Texts : String);
Begin Begin
MessageView.Items.Add(Texts); MessageView.Items.Add(Texts);
end; end;

View File

@ -1369,8 +1369,9 @@ end;
destructor TSourceNotebook.Destroy; destructor TSourceNotebook.Destroy;
var i: integer; var i: integer;
begin begin
writeln('[TSourceNotebook.Destroy]');
for i:=FSourceEditorList.Count-1 downto 0 do for i:=FSourceEditorList.Count-1 downto 0 do
Editors[EditorCount-1].Free; Editors[i].Free;
if Notebook<>nil then begin if Notebook<>nil then begin
Notebook.Free; Notebook.Free;
NoteBook:=nil; NoteBook:=nil;
@ -1843,10 +1844,11 @@ writeln('TSourceNotebook.NewSe A');
Notebook.Pages.Insert(PageNum,FindUniquePageName('',-1)); Notebook.Pages.Insert(PageNum,FindUniquePageName('',-1));
end; end;
Result := TSourceEditor.Create(Self,Notebook.Page[PageNum]); Result := TSourceEditor.Create(Self,Notebook.Page[PageNum]);
writeln('TSourceNotebook.NewSe B');
FSourceEditorList.Add(Result);
Result.FUnitName:=Notebook.Pages[PageNum]; Result.FUnitName:=Notebook.Pages[PageNum];
Result.CodeTemplates:=CodeTemplateModul; Result.CodeTemplates:=CodeTemplateModul;
Notebook.PageIndex := Pagenum; Notebook.PageIndex := Pagenum;
FSourceEditorList.Add(Result);
Result.EditorComponent.BookMarkOptions.BookmarkImages := MarksImgList; Result.EditorComponent.BookMarkOptions.BookmarkImages := MarksImgList;
Result.PopupMenu:=SrcPopupMenu; Result.PopupMenu:=SrcPopupMenu;
Result.OnEditorChange := @EditorChanged; Result.OnEditorChange := @EditorChanged;
@ -2170,7 +2172,6 @@ Begin
Result := GetActiveSE.FileName; Result := GetActiveSE.FileName;
end; end;
function TSourceNotebook.GetEditors(Index:integer):TSourceEditor; function TSourceNotebook.GetEditors(Index:integer):TSourceEditor;
begin begin
Result:=TSourceEditor(FSourceEditorList[Index]); Result:=TSourceEditor(FSourceEditorList[Index]);
@ -2212,7 +2213,6 @@ begin
Result:=Filename; Result:=Filename;
exit; exit;
end; end;
FileName:='unit1';
end; end;
ShortName:=ExtractFileName(FileName); ShortName:=ExtractFileName(FileName);
Ext:=ExtractFileExt(ShortName); Ext:=ExtractFileExt(ShortName);