Yeah, it's me again.
I've made a tiny program to convert hex strings in a copy-pasted block of text, into decimal numbers. But Lazarus doesn't like me deleting characters from a TStringList, for some reason.
It's under a hundred lines, so it's not some gargantuan mess.
Problem lines:
[spoiler]
Delete(tstrlistDest[iCounter], Pos(tstrlistDest[iCounter], strCurrentHex), iHexLength);
Insert(strDecimal, tstrlistDest[iCounter], iPos);
[/spoiler]
Current .pas:
[spoiler]
unit hextodeclistconv;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
StrUtils;
type
{ TformWindow }
TformWindow = class(TForm)
buttonBegin: TButton;
editBegin: TEdit;
editEnd: TEdit;
groupBegin: TGroupBox;
groupEnd: TGroupBox;
memoSource: TMemo;
memoResult: TMemo;
procedure buttonBeginClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
formWindow: TformWindow;
implementation
{$R *.lfm}
{ TformWindow }
var
tstrlistSource, tstrlistDest: TStringList;
procedure TformWindow.FormCreate(Sender: TObject);
begin
tstrlistSource := TStringList.Create;
tstrlistDest := TStringList.Create;
tstrlistSource.Sorted := false;
tstrlistDest.Sorted := false;
end;
function GetHexString(strLine: string; iPos, iNumChars: integer): string;
var
strHex: string;
begin
strHex := copy(strLine, iPos, iNumChars);
Result := strHex;
end;
procedure TformWindow.buttonBeginClick(Sender: TObject);
var
iCounter, iDecimal, iPos, iNumchars, iHexLength: integer;
strCurrentHex, strDecimal: string;
begin
tstrlistSource.Assign(memoSource.Lines);
tstrlistSource.Sorted := true;
tstrlistDest := tstrlistSource;
tstrlistDest.Sorted := true;
if editBegin.Text = '0' then
editBegin.Text := '1';
if editEnd.Text = '0' then
editEnd.Text := '1';
iPos := StrToInt(editBegin.Text);
iNumChars := StrToInt(EditEnd.Text);
for iCounter := 0 to tstrlistSource.Count - 1 do begin
strCurrentHex := GetHexString(tstrlistSource[iCounter], iPos, iNumChars);
iDecimal := Hex2Dec(strCurrentHex);
strDecimal := IntToStr(iDecimal);
iHexLength := Length(strCurrentHex);
Delete(tstrlistDest[iCounter], Pos(tstrlistDest[iCounter], strCurrentHex), iHexLength);
Insert(strDecimal, tstrlistDest[iCounter], iPos);
end;
memoResult.Lines.AddStrings(tstrlistDest);
end;
end.
[/spoiler]
Any idea what the error means?