hello,
old post but i have just found that you can use
TStringList in pascalscript of Macro Editor in Lazarus.
But you must do few changes in the unit
EMScriptClasses of macroscript component.
1 - in the uses add
uPSR_classes,
uPSC_classes units.
2 -In the function
CompilerOnUses replace :
SIRegisterTObject(Sender);
//SIRegister_Std(Sender);
with this :
SIRegisterTObject(Sender);
SIRegister_Std(Sender);
SIRegister_Classes(Sender, true);
3 - In the constructor
TEMSTPSExec.Create replace :
RIRegisterTObject(FCLassImp);
// ## RIRegister_Std(CL);
with this
RIRegisterTObject(FCLassImp);
RIRegister_Std(FCLassImp);
RIRegister_Classes(FCLassImp,true);
and now you should be able to use
tstringlist in your pascalscript scripts of the lazarus Macro Editor.
I did finally succeed in getting the BigChimp's (r.i.p) macro to work with some changes :
const lineEndingInt = #13#10;
lineEndingStr = '#13#10';
function QuotedStr(const S: string): string;
var
I: Integer;
begin
Result := S;
for I := Length(Result) downto 1 do
if Result[I] = '''' then Insert('''', Result, I);
Result := '''' + Result + '''';
end;
procedure PascalizeString(Source: string; var Target: TStringList);
var
i: integer;
begin
Target.Text:=Source;
for i:=0 to Target.Count-1 do
begin
if i<Target.Count-1 then
Target[i]:=QuotedStr(Target[i])+ ' + ' + LineEndingStr + ' +'
else
Target[i]:=QuotedStr(Target[i])+';';
end;
end;
var
i: integer;
First,Last: TPoint;
s: string;
SelectionText: string;
ResultList: TStringList;
begin
// Make sure text is selected:
if not Caller.SelAvail then exit;
First := Caller.BlockBegin;
Last := Caller.BlockEnd;
// Switch around if backward selection:
if (First.y > Last.y) or ((First.y = Last.y) and (First.x > Last.x)) then begin
First := Caller.BlockEnd;
Last := Caller.BlockBegin;
end;
// Copy over selected text
ResultList:=TStringList.Create;
try
for i:=First.y to Last.y do
begin
if i=First.y then
SelectionText:= copy(Caller.Lines[i-1],
First.x, length(Caller.Lines[i-1])- First.x +1)
else
SelectionText:=SelectionText+ LineEndingInt + Caller.Lines[i-1];
end;
PascalizeString(SelectionText,ResultList);
Caller.CutToClipBoard; //Cut out original text
ClipBoard.AsText:=ResultList.Text; //Assign our own variable
Caller.PasteFromClipBoard;
finally
ResultList.Free;
end;
end.
Works on Windows 10 Lazarus 2.0.12 fpc 3.2 and linux Ubuntu 20.04 LTS Lazarus 2.1.0 fpc 3.3.1
on linux modify the beginning of the macro with this :
const lineEndingInt = #10;
lineEndingStr = '#10';
in attachments :
2 - Use of the
MultilineStr Macro in Lazarus IDE (click on image to see animation).
Friendly, J.P