Registriert seit: 8. Sep 2008
134 Beiträge
|
AW: CreateUndoableWriter D11
10. Aug 2022, 12:09
Anbei ein Teil davon. Ist leider etwas größer:
Code:
function TUsesCleanerObj.DoCleanUnit(Editor: IOTASourceEditor; Intf, Impl:
TStrings): Boolean;
var
SrcStream: TMemoryStream;
Writer: IOTAEditWriter;
Buffer: IOTAEditBuffer;
Lex: TmwPasLex;
Source: AnsiString;
begin
Result := False;
if not Assigned(Editor) then begin
Exit;
end;
Buffer := (Editor as IOTAEditBuffer);
if Assigned(Buffer) then begin
if Buffer.IsReadOnly then begin
Exit;
end;
try
SrcStream := TMemoryStream.Create;
EditFilerSaveFileToStream(Editor.FileName, SrcStream);
// GxOtaSaveEditorToStream(Buffer, SrcStream, False, False);
Lex := TmwPasLex.Create;
Lex.Origin := PAnsiChar(SrcStream.Memory);
Buffer.EditOptions.BeginUpdate;
try
Writer := Buffer.CreateUndoableWriter;
try
while not (Lex.TokenID in [tkImplementation, tkUses, tkNull]) do
Lex.NextNoJunk;
if (Intf.Count > 0) and (Lex.TokenID = tkUses) then
begin
Writer.CopyTo(Lex.TokenPos);
Source := GetUsesSource(Intf);
Writer.DeleteTo(Lex.TokenPos);
if Source <> '' then
begin
Writer.Insert(PAnsiChar(ConvertToIDEEditorString(Source)));
end;
end;
Lex.Next;
if Impl.Count > 0 then
begin
while not (Lex.TokenID in [tkUses, tkNull]) do
Lex.NextNoJunk;
if Lex.TokenID = tkUses then
begin
Writer.CopyTo(Lex.TokenPos);
Source := GetUsesSource(Impl);
Writer.DeleteTo(Lex.TokenPos);
if Source <> '' then
begin
Writer.Insert(PAnsiChar(ConvertToIDEEditorString(Source)));
end;
end;
end;
Result := True;
finally
FreeAndNil(Lex);
FreeAndNil(SrcStream);
Writer := nil;
end;
finally
Buffer.EditOptions.EndUpdate;
end;
except
;
end;
end;
end;
|
|
Zitat
|