mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 14:36:09 +02:00
MG: codetools accelerated
git-svn-id: trunk@270 -
This commit is contained in:
parent
99383a228a
commit
ddb43ba20d
200
ide/codetools.pp
200
ide/codetools.pp
@ -33,7 +33,7 @@ type
|
|||||||
LineEnds: integer;
|
LineEnds: integer;
|
||||||
LengthOfLastLine: integer;
|
LengthOfLastLine: integer;
|
||||||
Operation: TSourceLogEntryOperation;
|
Operation: TSourceLogEntryOperation;
|
||||||
constructor Create(APos, ALength, AMoveTo: integer; Txt: string;
|
constructor Create(APos, ALength, AMoveTo: integer; const Txt: string;
|
||||||
AnOperation: TSourceLogEntryOperation);
|
AnOperation: TSourceLogEntryOperation);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ type
|
|||||||
|
|
||||||
TSourceLog = class;
|
TSourceLog = class;
|
||||||
|
|
||||||
TOnSourceLogInsert = procedure(Sender: TSourceLog; Pos: integer; Txt: string)
|
TOnSourceLogInsert = procedure(Sender: TSourceLog; Pos: integer;
|
||||||
of object;
|
const Txt: string) of object;
|
||||||
TOnSourceLogDelete = procedure(Sender: TSourceLog; Pos, Len: integer)
|
TOnSourceLogDelete = procedure(Sender: TSourceLog; Pos, Len: integer)
|
||||||
of object;
|
of object;
|
||||||
TOnSourceLogMove = procedure(Sender: TSourceLog; Pos, Len, MoveTo: integer)
|
TOnSourceLogMove = procedure(Sender: TSourceLog; Pos, Len, MoveTo: integer)
|
||||||
@ -70,13 +70,14 @@ type
|
|||||||
FOnInsert: TOnSourceLogInsert;
|
FOnInsert: TOnSourceLogInsert;
|
||||||
FOnDelete: TOnSourceLogDelete;
|
FOnDelete: TOnSourceLogDelete;
|
||||||
FOnMove: TOnSourceLogMove;
|
FOnMove: TOnSourceLogMove;
|
||||||
procedure SetSource(NewSrc: string);
|
procedure SetSource(const NewSrc: string);
|
||||||
function GetItems(Index: integer): TSourceLogEntry;
|
function GetItems(Index: integer): TSourceLogEntry;
|
||||||
procedure SetItems(Index: integer; AnItem: TSourceLogEntry);
|
procedure SetItems(Index: integer; AnItem: TSourceLogEntry);
|
||||||
function GetMarkers(Index: integer): TSourceLogMarker;
|
function GetMarkers(Index: integer): TSourceLogMarker;
|
||||||
procedure BuildLineRanges;
|
procedure BuildLineRanges;
|
||||||
public
|
public
|
||||||
property Items[Index: integer]: TSourceLogEntry read GetItems write SetItems; default;
|
property Items[Index: integer]: TSourceLogEntry
|
||||||
|
read GetItems write SetItems; default;
|
||||||
function Count: integer;
|
function Count: integer;
|
||||||
property Markers[Index: integer]: TSourceLogMarker read GetMarkers;
|
property Markers[Index: integer]: TSourceLogMarker read GetMarkers;
|
||||||
function MarkerCount: integer;
|
function MarkerCount: integer;
|
||||||
@ -86,15 +87,15 @@ type
|
|||||||
property Modified: boolean read FModified write FModified;
|
property Modified: boolean read FModified write FModified;
|
||||||
procedure LineColToPosition(Line, Column: integer; var Position: integer);
|
procedure LineColToPosition(Line, Column: integer; var Position: integer);
|
||||||
procedure AbsoluteToLineCol(Position: integer; var Line, Column: integer);
|
procedure AbsoluteToLineCol(Position: integer; var Line, Column: integer);
|
||||||
procedure Insert(Pos: integer; Txt: string);
|
procedure Insert(Pos: integer; const Txt: string);
|
||||||
procedure Delete(Pos, Len: integer);
|
procedure Delete(Pos, Len: integer);
|
||||||
procedure Replace(Pos, Len: integer; Txt: string);
|
procedure Replace(Pos, Len: integer; const Txt: string);
|
||||||
procedure Move(Pos, Len, MoveTo: integer);
|
procedure Move(Pos, Len, MoveTo: integer);
|
||||||
property OnInsert: TOnSourceLogInsert read FOnInsert write FOnInsert;
|
property OnInsert: TOnSourceLogInsert read FOnInsert write FOnInsert;
|
||||||
property OnDelete: TOnSourceLogDelete read FOnDelete write FOnDelete;
|
property OnDelete: TOnSourceLogDelete read FOnDelete write FOnDelete;
|
||||||
property OnMove: TOnSourceLogMove read FOnMove write FOnMove;
|
property OnMove: TOnSourceLogMove read FOnMove write FOnMove;
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
constructor Create(ASource: string);
|
constructor Create(const ASource: string);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -174,7 +175,8 @@ type
|
|||||||
ctnProcedureName:=7, ctnParameterList:=8,
|
ctnProcedureName:=7, ctnParameterList:=8,
|
||||||
ctnFunctionType:=9, ctnProcedureModifier:=10,
|
ctnFunctionType:=9, ctnProcedureModifier:=10,
|
||||||
ctnBeginBlock:=11, ctnAsmBlock:=12,
|
ctnBeginBlock:=11, ctnAsmBlock:=12,
|
||||||
ctnInterface:=20, ctnImplementation:=21, ctnInitialization:=22, ctnFinalization:=23
|
ctnInterface:=20, ctnImplementation:=21, ctnInitialization:=22,
|
||||||
|
ctnFinalization:=23
|
||||||
);
|
);
|
||||||
TCodeTreeNodeDescs = set of TCodeTreeNodeDesc;
|
TCodeTreeNodeDescs = set of TCodeTreeNodeDesc;
|
||||||
|
|
||||||
@ -321,83 +323,85 @@ type
|
|||||||
|
|
||||||
// program name
|
// program name
|
||||||
function RenameProgramInSource(Source:TSourceLog;
|
function RenameProgramInSource(Source:TSourceLog;
|
||||||
NewProgramName:string):boolean;
|
const NewProgramName:string):boolean;
|
||||||
function FindProgramNameInSource(Source:string;
|
function FindProgramNameInSource(const Source:string;
|
||||||
var ProgramNameStart,ProgramNameEnd:integer):string;
|
var ProgramNameStart,ProgramNameEnd:integer):string;
|
||||||
|
|
||||||
// unit name
|
// unit name
|
||||||
function RenameUnitInSource(Source:TSourceLog; NewUnitName:string):boolean;
|
function RenameUnitInSource(Source:TSourceLog;
|
||||||
function FindUnitNameInSource(Source:string;
|
const NewUnitName:string):boolean;
|
||||||
|
function FindUnitNameInSource(const Source:string;
|
||||||
var UnitNameStart,UnitNameEnd:integer):string;
|
var UnitNameStart,UnitNameEnd:integer):string;
|
||||||
|
|
||||||
// uses sections
|
// uses sections
|
||||||
function UnitIsUsedInSource(Source,UnitName:string):boolean;
|
function UnitIsUsedInSource(const Source,UnitName:string):boolean;
|
||||||
function RenameUnitInProgramUsesSection(Source:TSourceLog;
|
function RenameUnitInProgramUsesSection(Source:TSourceLog;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
function AddToProgramUsesSection(Source:TSourceLog;
|
function AddToProgramUsesSection(Source:TSourceLog;
|
||||||
AUnitName,InFileName:string):boolean;
|
const AUnitName,InFileName:string):boolean;
|
||||||
function RemoveFromProgramUsesSection(Source:TSourceLog;
|
function RemoveFromProgramUsesSection(Source:TSourceLog;
|
||||||
AUnitName:string):boolean;
|
const AUnitName:string):boolean;
|
||||||
function RenameUnitInInterfaceUsesSection(Source:TSourceLog;
|
function RenameUnitInInterfaceUsesSection(Source:TSourceLog;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
function AddToInterfaceUsesSection(Source:TSourceLog;
|
function AddToInterfaceUsesSection(Source:TSourceLog;
|
||||||
AUnitName,InFileName:string):boolean;
|
const AUnitName,InFileName:string):boolean;
|
||||||
function RemoveFromInterfaceUsesSection(Source:TSourceLog;
|
function RemoveFromInterfaceUsesSection(Source:TSourceLog;
|
||||||
AUnitName:string):boolean;
|
const AUnitName:string):boolean;
|
||||||
|
|
||||||
// single uses section
|
// single uses section
|
||||||
function IsUnitUsedInUsesSection(Source,UnitName:string;
|
function IsUnitUsedInUsesSection(const Source,UnitName:string;
|
||||||
UsesStart:integer):boolean;
|
UsesStart:integer):boolean;
|
||||||
function RenameUnitInUsesSection(Source:TSourceLog; UsesStart: integer;
|
function RenameUnitInUsesSection(Source:TSourceLog; UsesStart: integer;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
function AddUnitToUsesSection(Source:TSourceLog; UnitName,InFilename:string;
|
function AddUnitToUsesSection(Source:TSourceLog;
|
||||||
UsesStart:integer):boolean;
|
const UnitName,InFilename:string; UsesStart:integer):boolean;
|
||||||
function RemoveUnitFromUsesSection(Source:TSourceLog; UnitName:string;
|
function RemoveUnitFromUsesSection(Source:TSourceLog; const UnitName:string;
|
||||||
UsesStart:integer):boolean;
|
UsesStart:integer):boolean;
|
||||||
|
|
||||||
// compiler directives
|
// compiler directives
|
||||||
function FindIncludeDirective(Source,Section:string; Index:integer;
|
function FindIncludeDirective(const Source,Section:string; Index:integer;
|
||||||
var IncludeStart,IncludeEnd:integer):boolean;
|
var IncludeStart,IncludeEnd:integer):boolean;
|
||||||
function SplitCompilerDirective(Directive:string;
|
function SplitCompilerDirective(const Directive:string;
|
||||||
var DirectiveName,Parameters:string):boolean;
|
var DirectiveName,Parameters:string):boolean;
|
||||||
|
|
||||||
// createform
|
// createform
|
||||||
function AddCreateFormToProgram(Source:TSourceLog;
|
function AddCreateFormToProgram(Source:TSourceLog;
|
||||||
AClassName,AName:string):boolean;
|
const AClassName,AName:string):boolean;
|
||||||
function RemoveCreateFormFromProgram(Source:TSourceLog;
|
function RemoveCreateFormFromProgram(Source:TSourceLog;
|
||||||
AClassName,AName:string):boolean;
|
const AClassName,AName:string):boolean;
|
||||||
function CreateFormExistsInProgram(Source:string;
|
function CreateFormExistsInProgram(const Source, AClassName,
|
||||||
AClassName,AName:string):boolean;
|
AName:string):boolean;
|
||||||
function ListAllCreateFormsInProgram(Source:string):TStrings;
|
function ListAllCreateFormsInProgram(const Source:string):TStrings;
|
||||||
|
|
||||||
// resource code
|
// resource code
|
||||||
function FindResourceInCode(Source:string; AddCode:string;
|
function FindResourceInCode(const Source, AddCode:string;
|
||||||
var Position,EndPosition:integer):boolean;
|
var Position,EndPosition:integer):boolean;
|
||||||
function AddResourceCode(Source:TSourceLog; AddCode:string):boolean;
|
function AddResourceCode(Source:TSourceLog; const AddCode:string):boolean;
|
||||||
|
|
||||||
// form components
|
// form components
|
||||||
function FindFormClassDefinitionInSource(Source:string; FormClassName:string;
|
function FindFormClassDefinitionInSource(const Source, FormClassName:string;
|
||||||
var FormClassNameStartPos, FormBodyStartPos: integer
|
var FormClassNameStartPos, FormBodyStartPos: integer):boolean;
|
||||||
):boolean;
|
function FindFormComponentInSource(const Source: string;
|
||||||
function FindFormComponentInSource(Source: string; FormBodyStartPos: integer;
|
FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): integer;
|
ComponentName, ComponentClassName: string): integer;
|
||||||
function AddFormComponentToSource(Source:TSourceLog; FormBodyStartPos: integer;
|
function AddFormComponentToSource(Source:TSourceLog; FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): boolean;
|
const ComponentName, ComponentClassName: string): boolean;
|
||||||
function RemoveFormComponentFromSource(Source:TSourceLog; FormBodyStartPos: integer;
|
function RemoveFormComponentFromSource(Source:TSourceLog; FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): boolean;
|
ComponentName, ComponentClassName: string): boolean;
|
||||||
|
|
||||||
// code search
|
// code search
|
||||||
function SearchCodeInSource(Source,Find:string; StartPos:integer;
|
function SearchCodeInSource(const Source,Find:string; StartPos:integer;
|
||||||
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
|
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
|
||||||
procedure GetLineStartEndAtPosition(Source:string; Position:integer;
|
procedure GetLineStartEndAtPosition(const Source:string; Position:integer;
|
||||||
var LineStart,LineEnd:integer);
|
var LineStart,LineEnd:integer);
|
||||||
function ReadNextPascalAtom(Source:string;
|
function ReadNextPascalAtom(const Source:string;
|
||||||
var Position,AtomStart:integer):string;
|
var Position,AtomStart:integer):string;
|
||||||
function ReadRawNextPascalAtom(Source:string;
|
function ReadRawNextPascalAtom(const Source:string;
|
||||||
var Position,AtomStart:integer):string;
|
var Position,AtomStart:integer):string;
|
||||||
|
|
||||||
// utilities
|
// utilities
|
||||||
function LineEndCount(Txt: string; var LengthOfLastLine: integer): integer;
|
function LineEndCount(const Txt: string;
|
||||||
|
var LengthOfLastLine: integer): integer;
|
||||||
|
|
||||||
const
|
const
|
||||||
MaxLineLength:integer=80;
|
MaxLineLength:integer=80;
|
||||||
@ -430,7 +434,7 @@ type
|
|||||||
var
|
var
|
||||||
NodeMemManager: TCodeTreeNodeMemManager;
|
NodeMemManager: TCodeTreeNodeMemManager;
|
||||||
|
|
||||||
function FindIncludeDirective(Source,Section:string; Index:integer;
|
function FindIncludeDirective(const Source,Section:string; Index:integer;
|
||||||
var IncludeStart,IncludeEnd:integer):boolean;
|
var IncludeStart,IncludeEnd:integer):boolean;
|
||||||
var Atom,DirectiveName:string;
|
var Atom,DirectiveName:string;
|
||||||
Position,EndPos,AtomStart:integer;
|
Position,EndPos,AtomStart:integer;
|
||||||
@ -460,7 +464,7 @@ begin
|
|||||||
until Atom='';
|
until Atom='';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SplitCompilerDirective(Directive:string;
|
function SplitCompilerDirective(const Directive:string;
|
||||||
var DirectiveName,Parameters:string):boolean;
|
var DirectiveName,Parameters:string):boolean;
|
||||||
var EndPos,DirStart,DirEnd:integer;
|
var EndPos,DirStart,DirEnd:integer;
|
||||||
begin
|
begin
|
||||||
@ -482,7 +486,8 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RenameUnitInSource(Source:TSourceLog; NewUnitName:string):boolean;
|
function RenameUnitInSource(Source:TSourceLog;
|
||||||
|
const NewUnitName:string):boolean;
|
||||||
var UnitNameStart,UnitNameEnd:integer;
|
var UnitNameStart,UnitNameEnd:integer;
|
||||||
begin
|
begin
|
||||||
UnitNameStart:=0;
|
UnitNameStart:=0;
|
||||||
@ -492,7 +497,7 @@ begin
|
|||||||
Source.Replace(UnitNameStart,UnitNameEnd-UnitNameStart,NewUnitName);
|
Source.Replace(UnitNameStart,UnitNameEnd-UnitNameStart,NewUnitName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindUnitNameInSource(Source:string;
|
function FindUnitNameInSource(const Source:string;
|
||||||
var UnitNameStart,UnitNameEnd:integer):string;
|
var UnitNameStart,UnitNameEnd:integer):string;
|
||||||
begin
|
begin
|
||||||
UnitNameStart:=SearchCodeInSource(Source,'unit',1,UnitNameEnd,false);
|
UnitNameStart:=SearchCodeInSource(Source,'unit',1,UnitNameEnd,false);
|
||||||
@ -503,7 +508,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RenameProgramInSource(Source: TSourceLog;
|
function RenameProgramInSource(Source: TSourceLog;
|
||||||
NewProgramName:string):boolean;
|
const NewProgramName:string):boolean;
|
||||||
var ProgramNameStart,ProgramNameEnd:integer;
|
var ProgramNameStart,ProgramNameEnd:integer;
|
||||||
begin
|
begin
|
||||||
Result:=(FindProgramNameInSource(Source.Source,ProgramNameStart,ProgramNameEnd)<>'');
|
Result:=(FindProgramNameInSource(Source.Source,ProgramNameStart,ProgramNameEnd)<>'');
|
||||||
@ -511,7 +516,7 @@ begin
|
|||||||
Source.Replace(ProgramNameStart,ProgramNameEnd-ProgramNameStart,NewProgramName)
|
Source.Replace(ProgramNameStart,ProgramNameEnd-ProgramNameStart,NewProgramName)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindProgramNameInSource(Source:string;
|
function FindProgramNameInSource(const Source:string;
|
||||||
var ProgramNameStart,ProgramNameEnd:integer):string;
|
var ProgramNameStart,ProgramNameEnd:integer):string;
|
||||||
begin
|
begin
|
||||||
ProgramNameStart:=SearchCodeInSource(Source,'program',1,ProgramNameEnd,false);
|
ProgramNameStart:=SearchCodeInSource(Source,'program',1,ProgramNameEnd,false);
|
||||||
@ -521,7 +526,7 @@ begin
|
|||||||
Result:='';
|
Result:='';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UnitIsUsedInSource(Source,UnitName:string):boolean;
|
function UnitIsUsedInSource(const Source,UnitName:string):boolean;
|
||||||
// search in all uses sections
|
// search in all uses sections
|
||||||
var UsesStart,UsesEnd:integer;
|
var UsesStart,UsesEnd:integer;
|
||||||
begin
|
begin
|
||||||
@ -538,7 +543,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RenameUnitInProgramUsesSection(Source:TSourceLog;
|
function RenameUnitInProgramUsesSection(Source:TSourceLog;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
var
|
var
|
||||||
ProgramTermStart,ProgramTermEnd,
|
ProgramTermStart,ProgramTermEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -570,7 +575,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function AddToProgramUsesSection(Source:TSourceLog;
|
function AddToProgramUsesSection(Source:TSourceLog;
|
||||||
AUnitName,InFileName:string):boolean;
|
const AUnitName,InFileName:string):boolean;
|
||||||
var
|
var
|
||||||
ProgramTermStart,ProgramTermEnd,
|
ProgramTermStart,ProgramTermEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -603,7 +608,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RenameUnitInInterfaceUsesSection(Source:TSourceLog;
|
function RenameUnitInInterfaceUsesSection(Source:TSourceLog;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
var
|
var
|
||||||
InterfaceStart,InterfaceWordEnd,
|
InterfaceStart,InterfaceWordEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -630,7 +635,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function AddToInterfaceUsesSection(Source:TSourceLog;
|
function AddToInterfaceUsesSection(Source:TSourceLog;
|
||||||
AUnitName,InFileName:string):boolean;
|
const AUnitName,InFileName:string):boolean;
|
||||||
var
|
var
|
||||||
InterfaceStart,InterfaceWordEnd,
|
InterfaceStart,InterfaceWordEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -657,7 +662,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RemoveFromProgramUsesSection(Source:TSourceLog;
|
function RemoveFromProgramUsesSection(Source:TSourceLog;
|
||||||
AUnitName:string):boolean;
|
const AUnitName:string):boolean;
|
||||||
var
|
var
|
||||||
ProgramTermStart,ProgramTermEnd,
|
ProgramTermStart,ProgramTermEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -682,7 +687,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RemoveFromInterfaceUsesSection(Source:TSourceLog;
|
function RemoveFromInterfaceUsesSection(Source:TSourceLog;
|
||||||
AUnitName:string):boolean;
|
const AUnitName:string):boolean;
|
||||||
var
|
var
|
||||||
InterfaceStart,InterfaceWordEnd,
|
InterfaceStart,InterfaceWordEnd,
|
||||||
UsesStart,UsesEnd:integer;
|
UsesStart,UsesEnd:integer;
|
||||||
@ -701,7 +706,7 @@ begin
|
|||||||
Result:=RemoveUnitFromUsesSection(Source,AUnitName,UsesStart);
|
Result:=RemoveUnitFromUsesSection(Source,AUnitName,UsesStart);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsUnitUsedInUsesSection(Source,UnitName:string;
|
function IsUnitUsedInUsesSection(const Source,UnitName:string;
|
||||||
UsesStart:integer):boolean;
|
UsesStart:integer):boolean;
|
||||||
var UsesEnd:integer;
|
var UsesEnd:integer;
|
||||||
Atom:string;
|
Atom:string;
|
||||||
@ -729,10 +734,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RenameUnitInUsesSection(Source:TSourceLog; UsesStart: integer;
|
function RenameUnitInUsesSection(Source:TSourceLog; UsesStart: integer;
|
||||||
OldUnitName, NewUnitName, NewInFile:string): boolean;
|
const OldUnitName, NewUnitName, NewInFile:string): boolean;
|
||||||
var UsesEnd:integer;
|
var UsesEnd:integer;
|
||||||
LineStart,LineEnd,OldUsesStart:integer;
|
LineStart,LineEnd,OldUsesStart:integer;
|
||||||
s,Atom:string;
|
s,Atom,InFilePhrase:string;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (OldUnitName='') then begin
|
if (OldUnitName='') then begin
|
||||||
@ -745,7 +750,9 @@ begin
|
|||||||
if not (lowercase(copy(Source.Source,UsesStart,4))='uses') then exit;
|
if not (lowercase(copy(Source.Source,UsesStart,4))='uses') then exit;
|
||||||
// parse through all used units and see if it is already there
|
// parse through all used units and see if it is already there
|
||||||
if NewInFile<>'' then
|
if NewInFile<>'' then
|
||||||
NewInFile:=' in '''+NewInFile+'''';
|
InFilePhrase:=' in '''+NewInFile+''''
|
||||||
|
else
|
||||||
|
InFilePhrase:='';
|
||||||
s:=', ';
|
s:=', ';
|
||||||
repeat
|
repeat
|
||||||
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
|
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
|
||||||
@ -769,18 +776,18 @@ begin
|
|||||||
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
|
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
|
||||||
until Atom<>',';
|
until Atom<>',';
|
||||||
// unit not used yet -> add it
|
// unit not used yet -> add it
|
||||||
Source.Insert(UsesStart,s+NewUnitName+NewInFile);
|
Source.Insert(UsesStart,s+NewUnitName+InFilePhrase);
|
||||||
GetLineStartEndAtPosition(Source.Source,UsesStart,LineStart,LineEnd);
|
GetLineStartEndAtPosition(Source.Source,UsesStart,LineStart,LineEnd);
|
||||||
if (LineEnd-LineStart>MaxLineLength) or (NewInFile<>'') then
|
if (LineEnd-LineStart>MaxLineLength) or (InFilePhrase<>'') then
|
||||||
Source.Insert(UsesStart,EndOfLine+' ');
|
Source.Insert(UsesStart,EndOfLine+' ');
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AddUnitToUsesSection(Source:TSourceLog; UnitName,InFilename:string;
|
function AddUnitToUsesSection(Source:TSourceLog;
|
||||||
UsesStart:integer):boolean;
|
const UnitName,InFilename:string; UsesStart:integer):boolean;
|
||||||
var UsesEnd:integer;
|
var UsesEnd:integer;
|
||||||
LineStart,LineEnd:integer;
|
LineStart,LineEnd:integer;
|
||||||
s,Atom:string;
|
s,Atom,InFilenamePhrase:string;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (UnitName='') or (UnitName=';') or (UsesStart<1) then exit;
|
if (UnitName='') or (UnitName=';') or (UsesStart<1) then exit;
|
||||||
@ -804,15 +811,17 @@ begin
|
|||||||
until Atom<>',';
|
until Atom<>',';
|
||||||
// unit not used yet -> add it
|
// unit not used yet -> add it
|
||||||
if InFilename<>'' then
|
if InFilename<>'' then
|
||||||
InFileName:=' in '''+InFileName+'''';
|
InFileNamePhrase:=' in '''+InFileName+''''
|
||||||
Source.Insert(UsesStart,s+UnitName+InFileName);
|
else
|
||||||
|
InFilenamePhrase:='';
|
||||||
|
Source.Insert(UsesStart,s+UnitName+InFileNamePhrase);
|
||||||
GetLineStartEndAtPosition(Source.Source,UsesStart,LineStart,LineEnd);
|
GetLineStartEndAtPosition(Source.Source,UsesStart,LineStart,LineEnd);
|
||||||
if (LineEnd-LineStart>MaxLineLength) or (InFileName<>'') then
|
if (LineEnd-LineStart>MaxLineLength) or (InFileNamePhrase<>'') then
|
||||||
Source.Insert(UsesStart,EndOfLine+' ');
|
Source.Insert(UsesStart,EndOfLine+' ');
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RemoveUnitFromUsesSection(Source:TSourceLog; UnitName:string;
|
function RemoveUnitFromUsesSection(Source:TSourceLog; const UnitName:string;
|
||||||
UsesStart:integer):boolean;
|
UsesStart:integer):boolean;
|
||||||
var UsesEnd,OldUsesStart,OldUsesEnd:integer;
|
var UsesEnd,OldUsesStart,OldUsesEnd:integer;
|
||||||
Atom:string;
|
Atom:string;
|
||||||
@ -853,7 +862,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function AddCreateFormToProgram(Source:TSourceLog;
|
function AddCreateFormToProgram(Source:TSourceLog;
|
||||||
AClassName,AName:string):boolean;
|
const AClassName,AName:string):boolean;
|
||||||
// insert 'Application.CreateForm(<AClassName>,<AName>);'
|
// insert 'Application.CreateForm(<AClassName>,<AName>);'
|
||||||
// in front of 'Application.Run;'
|
// in front of 'Application.Run;'
|
||||||
var Position,EndPosition:integer;
|
var Position,EndPosition:integer;
|
||||||
@ -868,7 +877,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function RemoveCreateFormFromProgram(Source:TSourceLog;
|
function RemoveCreateFormFromProgram(Source:TSourceLog;
|
||||||
AClassName,AName:string):boolean;
|
const AClassName,AName:string):boolean;
|
||||||
// remove 'Application.CreateForm(<AClassName>,<AName>);'
|
// remove 'Application.CreateForm(<AClassName>,<AName>);'
|
||||||
var Position,EndPosition,AtomStart:integer;
|
var Position,EndPosition,AtomStart:integer;
|
||||||
begin
|
begin
|
||||||
@ -883,7 +892,7 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateFormExistsInProgram(Source:string;
|
function CreateFormExistsInProgram(const Source,
|
||||||
AClassName,AName:string):boolean;
|
AClassName,AName:string):boolean;
|
||||||
var Position,EndPosition:integer;
|
var Position,EndPosition:integer;
|
||||||
begin
|
begin
|
||||||
@ -892,7 +901,7 @@ begin
|
|||||||
Result:=Position>0;
|
Result:=Position>0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ListAllCreateFormsInProgram(Source:string):TStrings;
|
function ListAllCreateFormsInProgram(const Source:string):TStrings;
|
||||||
// list format: <formname>:<formclassname>
|
// list format: <formname>:<formclassname>
|
||||||
var Position,EndPosition:integer;
|
var Position,EndPosition:integer;
|
||||||
s:string;
|
s:string;
|
||||||
@ -906,13 +915,12 @@ begin
|
|||||||
s:=ReadNextPascalAtom(Source,EndPosition,Position);
|
s:=ReadNextPascalAtom(Source,EndPosition,Position);
|
||||||
ReadNextPascalAtom(Source,EndPosition,Position);
|
ReadNextPascalAtom(Source,EndPosition,Position);
|
||||||
s:=ReadNextPascalAtom(Source,EndPosition,Position)+':'+s;
|
s:=ReadNextPascalAtom(Source,EndPosition,Position)+':'+s;
|
||||||
writeln('ListAllCreateFormsInProgram ',s);
|
|
||||||
Result.Add(s);
|
Result.Add(s);
|
||||||
end;
|
end;
|
||||||
until Position<1;
|
until Position<1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindResourceInCode(Source:string; AddCode:string;
|
function FindResourceInCode(const Source, AddCode:string;
|
||||||
var Position,EndPosition:integer):boolean;
|
var Position,EndPosition:integer):boolean;
|
||||||
var Find,Atom:string;
|
var Find,Atom:string;
|
||||||
FindPosition,FindAtomStart,SemicolonPos:integer;
|
FindPosition,FindAtomStart,SemicolonPos:integer;
|
||||||
@ -939,7 +947,7 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AddResourceCode(Source:TSourceLog; AddCode:string):boolean;
|
function AddResourceCode(Source:TSourceLog; const AddCode:string):boolean;
|
||||||
var StartPos,EndPos:integer;
|
var StartPos,EndPos:integer;
|
||||||
begin
|
begin
|
||||||
if FindResourceInCode(Source.Source,AddCode,StartPos,EndPos) then begin
|
if FindResourceInCode(Source.Source,AddCode,StartPos,EndPos) then begin
|
||||||
@ -952,9 +960,8 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindFormClassDefinitionInSource(Source:string; FormClassName:string;
|
function FindFormClassDefinitionInSource(const Source, FormClassName:string;
|
||||||
var FormClassNameStartPos, FormBodyStartPos: integer
|
var FormClassNameStartPos, FormBodyStartPos: integer):boolean;
|
||||||
):boolean;
|
|
||||||
var AtomEnd,AtomStart: integer;
|
var AtomEnd,AtomStart: integer;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
@ -968,7 +975,8 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindFormComponentInSource(Source: string; FormBodyStartPos: integer;
|
function FindFormComponentInSource(const Source: string;
|
||||||
|
FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): integer;
|
ComponentName, ComponentClassName: string): integer;
|
||||||
var AtomStart, OldPos: integer;
|
var AtomStart, OldPos: integer;
|
||||||
Atom: string;
|
Atom: string;
|
||||||
@ -996,7 +1004,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function AddFormComponentToSource(Source:TSourceLog; FormBodyStartPos: integer;
|
function AddFormComponentToSource(Source:TSourceLog; FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): boolean;
|
const ComponentName, ComponentClassName: string): boolean;
|
||||||
var Position, AtomStart: integer;
|
var Position, AtomStart: integer;
|
||||||
Atom: string;
|
Atom: string;
|
||||||
PriorSpaces, NextSpaces: string;
|
PriorSpaces, NextSpaces: string;
|
||||||
@ -1035,12 +1043,12 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RemoveFormComponentFromSource(Source:TSourceLog; FormBodyStartPos: integer;
|
function RemoveFormComponentFromSource(Source:TSourceLog;
|
||||||
|
FormBodyStartPos: integer;
|
||||||
ComponentName, ComponentClassName: string): boolean;
|
ComponentName, ComponentClassName: string): boolean;
|
||||||
var AtomStart, Position, ComponentStart, LineStart, LineEnd: integer;
|
var AtomStart, Position, ComponentStart, LineStart, LineEnd: integer;
|
||||||
Atom: string;
|
Atom: string;
|
||||||
begin
|
begin
|
||||||
writeln('[RemoveFormComponentFromSource] A ',FormBodyStartPos);
|
|
||||||
ComponentName:=lowercase(ComponentName);
|
ComponentName:=lowercase(ComponentName);
|
||||||
ComponentClassName:=lowercase(ComponentClassName);
|
ComponentClassName:=lowercase(ComponentClassName);
|
||||||
Position:=FormBodyStartPos;
|
Position:=FormBodyStartPos;
|
||||||
@ -1075,7 +1083,7 @@ writeln('[RemoveFormComponentFromSource] A ',FormBodyStartPos);
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SearchCodeInSource(Source,Find:string; StartPos:integer;
|
function SearchCodeInSource(const Source,Find:string; StartPos:integer;
|
||||||
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
|
var EndFoundPosition:integer; CaseSensitive:boolean):integer;
|
||||||
// search pascal atoms of Find in Source
|
// search pascal atoms of Find in Source
|
||||||
var FindAtomStart,FindPos,Position,AtomStart
|
var FindAtomStart,FindPos,Position,AtomStart
|
||||||
@ -1128,7 +1136,7 @@ begin
|
|||||||
until false;
|
until false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure GetLineStartEndAtPosition(Source:string; Position:integer;
|
procedure GetLineStartEndAtPosition(const Source:string; Position:integer;
|
||||||
var LineStart,LineEnd:integer);
|
var LineStart,LineEnd:integer);
|
||||||
begin
|
begin
|
||||||
LineStart:=Position;
|
LineStart:=Position;
|
||||||
@ -1140,7 +1148,8 @@ begin
|
|||||||
inc(LineEnd);
|
inc(LineEnd);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ReadNextPascalAtom(Source:string; var Position,AtomStart:integer):string;
|
function ReadNextPascalAtom(const Source:string;
|
||||||
|
var Position,AtomStart:integer):string;
|
||||||
var DirectiveName:string;
|
var DirectiveName:string;
|
||||||
DirStart,DirEnd,EndPos:integer;
|
DirStart,DirEnd,EndPos:integer;
|
||||||
begin
|
begin
|
||||||
@ -1170,7 +1179,7 @@ begin
|
|||||||
until false;
|
until false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ReadRawNextPascalAtom(Source:string;
|
function ReadRawNextPascalAtom(const Source:string;
|
||||||
var Position,AtomStart:integer):string;
|
var Position,AtomStart:integer):string;
|
||||||
var Len:integer;
|
var Len:integer;
|
||||||
c1,c2:char;
|
c1,c2:char;
|
||||||
@ -1307,7 +1316,8 @@ begin
|
|||||||
Result:=copy(Source,AtomStart,Position-AtomStart);
|
Result:=copy(Source,AtomStart,Position-AtomStart);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function LineEndCount(Txt: string; var LengthOfLastLine: integer): integer;
|
function LineEndCount(const Txt: string;
|
||||||
|
var LengthOfLastLine: integer): integer;
|
||||||
var i, LastLineEndPos: integer;
|
var i, LastLineEndPos: integer;
|
||||||
begin
|
begin
|
||||||
i:=1;
|
i:=1;
|
||||||
@ -1329,7 +1339,8 @@ end;
|
|||||||
|
|
||||||
{ TSourceLogEntry }
|
{ TSourceLogEntry }
|
||||||
|
|
||||||
constructor TSourceLogEntry.Create(APos, ALength, AMoveTo: integer; Txt: string;
|
constructor TSourceLogEntry.Create(APos, ALength, AMoveTo: integer;
|
||||||
|
const Txt: string;
|
||||||
AnOperation: TSourceLogEntryOperation);
|
AnOperation: TSourceLogEntryOperation);
|
||||||
begin
|
begin
|
||||||
Position:=APos;
|
Position:=APos;
|
||||||
@ -1343,7 +1354,7 @@ end;
|
|||||||
|
|
||||||
{ TSourceLog }
|
{ TSourceLog }
|
||||||
|
|
||||||
constructor TSourceLog.Create(ASource: string);
|
constructor TSourceLog.Create(const ASource: string);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FModified:=false;
|
FModified:=false;
|
||||||
@ -1403,13 +1414,13 @@ begin
|
|||||||
Result:=fMarkers.Count;
|
Result:=fMarkers.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSourceLog.SetSource(NewSrc: string);
|
procedure TSourceLog.SetSource(const NewSrc: string);
|
||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
FSource:=NewSrc;
|
FSource:=NewSrc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSourceLog.Insert(Pos: integer; Txt: string);
|
procedure TSourceLog.Insert(Pos: integer; const Txt: string);
|
||||||
var i: integer;
|
var i: integer;
|
||||||
begin
|
begin
|
||||||
if Assigned(FOnInsert) then FOnInsert(Self,Pos,Txt);
|
if Assigned(FOnInsert) then FOnInsert(Self,Pos,Txt);
|
||||||
@ -1444,7 +1455,7 @@ begin
|
|||||||
FModified:=true;
|
FModified:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSourceLog.Replace(Pos, Len: integer; Txt: string);
|
procedure TSourceLog.Replace(Pos, Len: integer; const Txt: string);
|
||||||
var i: integer;
|
var i: integer;
|
||||||
begin
|
begin
|
||||||
if Assigned(FOnDelete) then FOnDelete(Self,Pos,Len);
|
if Assigned(FOnDelete) then FOnDelete(Self,Pos,Len);
|
||||||
@ -2266,3 +2277,4 @@ finalization
|
|||||||
CodeToolFinal;
|
CodeToolFinal;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user