mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 06:37:22 +01:00
IDE: quick fix for local variable not initialized: add assignment
git-svn-id: trunk@47838 -
This commit is contained in:
parent
f4c1725bcd
commit
e6e06c00ca
@ -9,7 +9,7 @@ uses
|
||||
|
||||
implementation
|
||||
|
||||
procedure TestInteger(var i: integer);
|
||||
procedure TestInteger(i: integer);
|
||||
begin
|
||||
writeln(i);
|
||||
end;
|
||||
@ -21,5 +21,19 @@ begin
|
||||
TestInteger(i);
|
||||
end;
|
||||
|
||||
procedure TestLots({%H-}s: string; {%H-}c: char; {%H-}p: pointer);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure DoLots;
|
||||
var
|
||||
s: string;
|
||||
c: char;
|
||||
p: Pointer;
|
||||
begin
|
||||
TestLots(s,c,p);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
@ -5904,6 +5904,7 @@ resourcestring
|
||||
lisPageNameAlreadyExists = 'Page name "%s" already exists. Not added.';
|
||||
lisJumpToProcedure = 'Jump to procedure %s';
|
||||
lisFindDeclarationOf = 'Find Declaration of %s';
|
||||
lisInitializeLocalVariable = 'Initialize Local Variable';
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
object QFInitLocalVarDialog: TQFInitLocalVarDialog
|
||||
Left = 314
|
||||
Height = 240
|
||||
Height = 225
|
||||
Top = 251
|
||||
Width = 320
|
||||
Width = 564
|
||||
Caption = 'QFInitLocalVarDialog'
|
||||
ClientHeight = 240
|
||||
ClientWidth = 320
|
||||
ClientHeight = 225
|
||||
ClientWidth = 564
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '1.5'
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 36
|
||||
Top = 198
|
||||
Width = 308
|
||||
Top = 183
|
||||
Width = 552
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
@ -24,32 +24,53 @@ object QFInitLocalVarDialog: TQFInitLocalVarDialog
|
||||
TabOrder = 0
|
||||
ShowButtons = [pbOK, pbCancel]
|
||||
end
|
||||
object WhereRadioGroup: TRadioGroup
|
||||
Left = 6
|
||||
Height = 74
|
||||
Top = 6
|
||||
Width = 308
|
||||
Align = alTop
|
||||
AutoFill = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'WhereRadioGroup'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 177
|
||||
Top = 0
|
||||
Width = 564
|
||||
Align = alClient
|
||||
BevelOuter = bvNone
|
||||
ChildSizing.EnlargeHorizontal = crsScaleChilds
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
ClientHeight = 177
|
||||
ClientWidth = 564
|
||||
TabOrder = 1
|
||||
end
|
||||
object ValueGroupBox: TGroupBox
|
||||
Left = 6
|
||||
Height = 106
|
||||
Top = 86
|
||||
Width = 308
|
||||
Align = alClient
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'ValueGroupBox'
|
||||
TabOrder = 2
|
||||
object WhereRadioGroup: TRadioGroup
|
||||
Left = 6
|
||||
Height = 78
|
||||
Top = 6
|
||||
Width = 548
|
||||
AutoFill = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'WhereRadioGroup'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
TabOrder = 0
|
||||
end
|
||||
object ValueRadioGroup: TRadioGroup
|
||||
Left = 6
|
||||
Height = 77
|
||||
Top = 90
|
||||
Width = 548
|
||||
AutoFill = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'ValueRadioGroup'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -32,8 +32,11 @@ unit QFInitLocalVarDlg;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, contnrs, FileUtil, CodeToolManager, CodeCache, LazIDEIntf,
|
||||
Forms, Controls, Graphics, Dialogs, ButtonPanel, ExtCtrls, StdCtrls;
|
||||
Classes, SysUtils, Math, contnrs, LazLogger,
|
||||
Forms, Controls, Graphics, Dialogs, ButtonPanel, ExtCtrls, StdCtrls,
|
||||
CodeToolManager, CodeCache, StdCodeTools,
|
||||
LazIDEIntf, IDEDialogs,
|
||||
LazarusIDEStrConsts;
|
||||
|
||||
type
|
||||
|
||||
@ -41,11 +44,16 @@ type
|
||||
|
||||
TQFInitLocalVarDialog = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
ValueGroupBox: TGroupBox;
|
||||
Panel1: TPanel;
|
||||
ValueRadioGroup: TRadioGroup;
|
||||
WhereRadioGroup: TRadioGroup;
|
||||
procedure ButtonPanel1OKButtonClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
public
|
||||
Statements: TStrings;
|
||||
InsertPositions: TObjectList;
|
||||
procedure Init(TheStatements: TStrings; TheInsertPositions: TObjectList);
|
||||
end;
|
||||
|
||||
function QuickFixLocalVarNotInitialized(Code: TCodeBuffer; X, Y: integer;
|
||||
@ -58,19 +66,42 @@ function QuickFixLocalVarNotInitialized(Code: TCodeBuffer; X, Y: integer;
|
||||
var
|
||||
Statements: TStrings;
|
||||
InsertPositions: TObjectList;
|
||||
Dlg: TQFInitLocalVarDialog;
|
||||
begin
|
||||
Result:=false;
|
||||
if not CodeToolBoss.GetPossibleInitsForVariable(Code,X,Y,Statements,
|
||||
InsertPositions)
|
||||
then begin
|
||||
if CodeToolBoss.ErrorCode<>nil then
|
||||
LazarusIDE.DoJumpToCodeToolBossError
|
||||
else
|
||||
ShowMessage('CodeToolBoss.GetPossibleInitsForVariable failed at '+Code.Filename+'('+IntToStr(Y)+','+IntToStr(X)+')');
|
||||
exit;
|
||||
end;
|
||||
Statements:=nil;
|
||||
InsertPositions:=nil;
|
||||
try
|
||||
if not CodeToolBoss.GetPossibleInitsForVariable(Code,X,Y,Statements,
|
||||
InsertPositions)
|
||||
then begin
|
||||
if CodeToolBoss.ErrorCode<>nil then
|
||||
LazarusIDE.DoJumpToCodeToolBossError
|
||||
else
|
||||
ShowMessage('CodeToolBoss.GetPossibleInitsForVariable failed at '+Code.Filename+'('+IntToStr(Y)+','+IntToStr(X)+')');
|
||||
exit;
|
||||
end;
|
||||
|
||||
ShowMessage('QuickFixLocalVarNotInitialized not yet implemented');
|
||||
Dlg:=TQFInitLocalVarDialog.Create(nil);
|
||||
try
|
||||
Dlg.Init(Statements,InsertPositions);
|
||||
case Dlg.ShowModal of
|
||||
mrOk: Result:=true;
|
||||
mrAbort:
|
||||
if CodeToolBoss.ErrorCode<>nil then
|
||||
LazarusIDE.DoJumpToCodeToolBossError
|
||||
else
|
||||
IDEMessageDialog('Error','Unable to insert the code',mtError,[mbOk]);
|
||||
else
|
||||
// user cancel
|
||||
end;
|
||||
finally
|
||||
Dlg.Free;
|
||||
end;
|
||||
finally
|
||||
Statements.Free;
|
||||
InsertPositions.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$R *.lfm}
|
||||
@ -79,8 +110,59 @@ end;
|
||||
|
||||
procedure TQFInitLocalVarDialog.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Caption:='Initialize local variable';
|
||||
WhereRadioGroup.AutoSize:=true;
|
||||
Caption:=lisInitializeLocalVariable;
|
||||
ButtonPanel1.OKButton.OnClick:=@ButtonPanel1OKButtonClick;
|
||||
end;
|
||||
|
||||
procedure TQFInitLocalVarDialog.ButtonPanel1OKButtonClick(Sender: TObject);
|
||||
begin
|
||||
if CodeToolBoss.InsertStatements(
|
||||
TInsertStatementPosDescription(InsertPositions[Max(0,WhereRadioGroup.ItemIndex)]),
|
||||
Statements[Max(0,ValueRadioGroup.ItemIndex)])
|
||||
then begin
|
||||
ModalResult:=mrOk;
|
||||
end else begin
|
||||
ModalResult:=mrAbort;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQFInitLocalVarDialog.Init(TheStatements: TStrings;
|
||||
TheInsertPositions: TObjectList);
|
||||
var
|
||||
i: Integer;
|
||||
InsertPos: TInsertStatementPosDescription;
|
||||
sl: TStringList;
|
||||
s: String;
|
||||
CodeXY: TCodeXYPosition;
|
||||
begin
|
||||
Statements:=TheStatements;
|
||||
InsertPositions:=TheInsertPositions;
|
||||
sl:=TStringList.Create;
|
||||
try
|
||||
// show possible insert positions
|
||||
for i:=0 to InsertPositions.Count-1 do begin
|
||||
InsertPos:=TInsertStatementPosDescription(InsertPositions[i]);
|
||||
CodeXY:=InsertPos.CodeXYPos;
|
||||
s:=ExtractFileName(CodeXY.Code.Filename)
|
||||
+'('+IntToStr(CodeXY.Y)+','+IntToStr(CodeXY.X)+') '
|
||||
+InsertPos.Description;
|
||||
sl.Add(s);
|
||||
end;
|
||||
WhereRadioGroup.Items.Assign(sl);
|
||||
WhereRadioGroup.ItemIndex:=0;
|
||||
WhereRadioGroup.AutoSize:=true;
|
||||
WhereRadioGroup.Caption:='Insert where:';
|
||||
|
||||
// show possible statements
|
||||
sl.Clear;
|
||||
for s in Statements do
|
||||
sl.Add(DbgStr(s));
|
||||
ValueRadioGroup.Items.Assign(sl);
|
||||
ValueRadioGroup.ItemIndex:=0;
|
||||
ValueRadioGroup.Caption:='Insert what:';
|
||||
finally
|
||||
sl.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user