Bonfield
2011-03-21 05:21:41
Im trying to make a procedure that writes an ini of a custom type here is the codeprogram new;
type
TItem = record
Name: String;
Uptext: TStringArray;
Outline_Count: Integer;
Width: Integer;
Height: Integer;
Middle_Colour : Integer;
Red_Count: Integer;
Ref_ID: Integer;
WithdrawAmount: Integer;
end;
var
Item1, Item2, Item3 : TItem;
i, h : integer;
Item: Array of TItem;
procedure LoadRecords;
begin
with Item1 do
begin
Name := 'Item1';
UpText := ['Item1', 'tem1'];
Outline_Count := 141;
Width := 29;
Height := 13;
Middle_Colour := 2105392;
Red_Count := 0
Ref_ID := 12;
WithdrawAmount := 1;
end;
with Item2 do
begin
Name := 'Item2';
UpText := ['Item2', 'tem2'];
Outline_Count := 70;
Width := 29;
Height := 12;
Middle_Colour := 5731970;
Red_Count := 86;
Ref_ID := 13;
WithdrawAmount := 1;
end;
with Item3 do
begin
Name := 'Item3';
UpText := ['Item3', 'tem3'];
Outline_Count := 71;
Width := 39;
Height := 13;
Middle_Colour := 5863556;
Red_Count := 78;
Ref_ID := 14;
WithdrawAmount := 0;
end;
end;
begin
SetLength(Item, 3);
LoadRecords;
Item :=[Item1, Item2, Item3];
h := High(Item);
for i:= 0 to h do
begin
WriteINI(Item[i].Name+' Record', 'Name', Item[i].Name, ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'UpText', ToStr(Item[i].UpText), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Outline_Count', ToStr(Item[i].Outline_Count), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Width', ToStr(Item[i].Width), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Height', ToStr(Item[i].Height), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Middle_Colour', ToStr(Item[i].Middle_Colour), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Red_Count', ToStr(Item[i].Red_Count), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Ref_ID', ToStr(Item[i].Ref_ID), 'C:\Users\SAMSUNG\Desktop\New Folder\players.ini');
WriteINI(Item[i].Name+' Record', 'WithdrawAmount', ToStr(Item[i].WithdrawAmount), ScriptPath+'players.ini');
end;
end.it works fine once, but if I try to run it again I get this error
Error: Exception: Unable to create fileit cycles through Width, Ref_ID and UpText lines, i can not see what is causing thisalso I would like to compare the current ini with records created during runtime, i want this to eventually end up auto-updating my item records, what would be the easiest way to compare the values to see if an update is needed?
something like this?
function Item(ItemOutLine, ItemWidth, ItemHeight, ItemColor: Integer): TItem;
begin
with Result do
begin
OutLine := ItemOutLine;
Width := ItemWidth;
Height := ItemHeight;
Color := ItemColor;
//etc for the rest of the type
end;
end; and compare from there?