asked on
procedure TForm1.FormCreate(Sender: TObject);
var
cmp: TShape;
i: integer;
Fname:string;
begin //1
FShapeNumber := 0;
with TINIFile.Create(ExtractFilePath(Application.Exename) + 'yourini.ini')do begin //2
try //3
caption:= ReadString(Self.Name, 'Caption', Caption);
LoadBackground( ReadString('_global_', 'bitmapfile', '' ) );
pathstrBitmapFile:= ReadString('_global_', 'bitmapfile', '' );
n := ReadInteger(Self.Name, 'Shapes', 0);
for i := 1 to n do
begin //4
// if you use TShape as class, you only need to cast once
cmp := TShape(FindComponent('Shape' + IntToStr(i)));
if cmp = nil then
begin //5
cmp := TShape.Create(Self);
cmp.Name := 'Shape' + IntToStr(I);
cmp.Parent := Self;
cmp.onMouseDown := ShapeMouseDown;
cmp.onMouseMove := ShapeMouseMove;
cmp.onMouseUp := ShapeMouseUp;
cmp.Tag := FShapeNumber;
inc(FShapeNumber);
cmp.Brush.Color := TColor(ReadInteger(Self.Name, cmp.Name + ' Brush Color', integer(clGreen)));
cmp.Width := ReadInteger(Self.Name, cmp.Name + ' Width', cmp.Width);
cmp.Height := ReadInteger(Self.Name, cmp.Name + ' Height', cmp.Height);
cmp.Top := ReadInteger(Self.Name, cmp.Name + ' Top', cmp.Top);
cmp.Left := ReadInteger(Self.Name, cmp.Name + ' Left', cmp.Left);
cmp.hint :=readString(Self.Name, cmp.Name + ' Hint',TShape(cmp).Hint);
cmp.showhint :=readBool(Self.Name, cmp.Name + ' ShowHint',TShape(cmp).Showhint);
end; //5
end; // 4
finally
free;
end; //3
Application.Showhint := true;
end; //2
end; //1