procedure TForm1.ListBox1Click(Sender: TObject);
var
i, o, error: integer;
numX, numY,holX, holY, radX, scale: real;
varX, varY: string;
test : double;
X, Y, varX1, varY1, holX1, holY1, radX1: single;
NCList, sline: TStringList;
varprof: Ansistring;
nextline: boolean;
bmp: TBGRABitmap;
c: TBGRAPixel;
begin
i := ListBox1.ItemIndex;
if i < 0 then
begin
ProfileLabel.Caption := '';
ProfileLabel.Visible := False;
AmountLabel.Caption := '';
AmountLabel.Visible := False;
SteelQualLabel.Caption := '';
SteelQualLabel.Visible := False;
LengthLabel.Caption := '';
LengthLabel.Visible := False;
WidthLabel.Caption := '';
WidthLabel.Visible := False;
Exit; // -1 means there is no selected item
end;
try
ProjectNrLabel.Visible := True;
ProfileLabel.Visible := True;
AmountLabel.Visible := True;
SteelQualLabel.Visible := True;
LengthLabel.Visible := True;
WidthText.Visible := True;
WidthLabel.Visible := True;
NCList := TStringList.Create;
sline := TStringList.Create;
NCList.LoadFromFile(ListBox1.Items[i]);
if NCList.Count >= 3 then
ProjectNrLabel.Caption := Trim(NCList[2]);
if NCList.Count >= 7 then
SteelQualLabel.Caption := Trim(NCList[6]);
if NCList.Count >= 8 then
AmountLabel.Caption := Trim(NCList[7]);
if NCList.Count >= 9 then
ProfileLabel.Caption := Trim(NCList[8]);
if NCList.Count >= 11 then
varX := NCList[10];
if NCList.Count >= 12 then
varY := NCList[11];
if NCList.Count >= 11 then
LengthLabel.Caption := Trim(NCList[10]);
if NCList.Count >= 13 then
WidthLabel.Caption := Trim(NCList[12]);
//
Val(varX,numX,error);
Val(varY,numY,error);
VarX1:=numX+20;
VarY1:=numY+20;
PaintBox1.Canvas.Clear();
bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height,BGRAWhite);
c := ColorToBGRA(ColorToRGB(clWindowText));
bmp.JoinStyle := pjsRound;
X:= (PaintBox1.Width / 2);
Y:= (PaintBox1.Height / 2);
if NCList.Count >= 10 then
begin
varprof := Trim(NCList[9]);
end;
// I selection to bitmap
if varprof = ('I') then
begin
if VarX1 > (X*2+30) then
begin
scale := VarX1 / (X*2);
varX1 := VarX1 / scale;
VarY1 := VarY1 / scale;
end;
bmp.LineCap := pecSquare;
bmp.PenStyle := psSolid;
bmp.DrawPolylineAntialias([PointF(10,50), PointF(VarX1,50), PointF(VarX1,VarY1), PointF(10,VarY1), PointF(10,50)],c,3);
bmp.Draw(PaintBox1.Canvas,0,0,False);
bmp.Free;
end;
// B selection to bitmap
if varprof = ('B') then
begin
WidthLabel.Visible := False;
WidthText.Visible := False;
if VarX1 > (X*2+30) then
begin
scale := VarX1 / (X*2);
varX1 := VarX1 / scale;
VarY1 := VarY1 / scale;
end;
try
for o := 27 {or 27 if you are sure about 27} to NCList.Count - 1 do
case NCList[o] of
'BO': nextline := True;
'EN': nextline := False;
else
begin
if nextline then
begin
sline.CommaText := NCList[o];
// do what you want with it
Val(sline.ValueFromIndex[1],holX,error);
Val(sline.ValueFromIndex[2],holY,error);
Val(sline.ValueFromIndex[3],radX,error);
holX1 := holX;
holY1 := holY;
radX1 := radX/2;
//test := (holX1);
bmp.LineCap := pecSquare;
bmp.PenStyle := psSolid;
bmp.EllipseAntialias(holX1,holY1,radX1,radX1,c,3);
end;
end;
end
finally
sline.free;
end;
bmp.LineCap := pecSquare;
bmp.PenStyle := psSolid;
bmp.DrawPolylineAntialias([PointF(10,50), PointF(VarX1,50), PointF(VarX1,VarY1), PointF(10,VarY1), PointF(10,50)],c,3);
bmp.Draw(PaintBox1.Canvas,0,0,False);
bmp.Free;
end;
//ShowMessage('Error');
finally
if Assigned(NCList) then
FreeAndNil(NCList);
end;
end;