Board index » delphi » Can someone please help?

Can someone please help?

Hi there,

Using D4 C/S and Paradox Tables...

I am currently doing the following in a function which works ok:

          case Photo1Combo.ItemIndex of
               0 : begin
DM.AssessmentsPhoto01.LoadFromFile(openDialog1.filename);
                   end;
               1 : begin
DM.AssessmentsPhoto02.LoadFromFile(openDialog1.filename);
                   end;
               2 : begin
DM.AssessmentsPhoto03.LoadFromFile(openDialog1.filename);
                   end;
.
.
.

              29 : begin
DM.AssessmentsPhoto30.LoadFromFile(openDialog1.filename);
                   end;
          end;

I want to be able to do this in one statement if possible. The
following compiles but gets an exception error when executed:

TBlobField(FindComponent('DM.AssessmentsPhoto0'+IntToStr(Photo1Combo.ItemIndex+1))).LoadFromFile(openDialog1.filename);

Can someone explain why and/or how to make this work please...

Thanks in advance,

Robbie...

 

Re:Can someone please help?


Simple solution put references to AssessmentsPhoto01..29 to array then access it by index.
Or as you proposed:
TBlobField(DM.FindComponent('DM.AssessmentsPhoto0'+IntToStr(Photo1Combo.ItemIndex+1))).LoadFromFile(openDialog1.filename);

Re:Can someone please help?


Its possible that there is no component with the name you are constructing,
i.e. no 'DM.AssessmentsPhoto029'.

Quote

>TBlobField(FindComponent('DM.AssessmentsPhoto0'+IntToStr(Photo1Combo.ItemIn

dex+1))).LoadFromFile(openDialog1.filename);

var    bf    : tBlobField;

bf := tBlobField (DM.FieldByName ('AssessmentsPhoto' + Format ('%.2d',
[Photo1Combo.ItemIndex + 1])));
if bf <> nil
then bf.LoadFromFile (openDialog1.FileName)            // presuming that
openDialog1.FileName contains a valid file name
else // do some error processing

Re:Can someone please help?


Hi Robbie!

An example with 30 images:

var Images:array[1..30]of integer;

eg.by FormCreate:
var i, counter: integer;
begin  
   counter:=1;
   for i:=0 to ComponentCount-1 do
       if TObject(Form1.Components[i]) is TImage then begin
          Images[counter]:=i;
          inc(counter);
       end;
...

TImage(components(Images[Photo1Combo.ItemIndex])).LoadFromFile(OpenDia...);

You can do the same for all kind of components.

Cheers,
Rudy
============================
Robbie schreef:

Quote

> Using D4 C/S and Paradox Tables...

> I am currently doing the following in a function which works ok:

>           case Photo1Combo.ItemIndex of
>                0 : begin
> DM.AssessmentsPhoto01.LoadFromFile(openDialog1.filename);
>                    end;
>                1 : begin
> DM.AssessmentsPhoto02.LoadFromFile(openDialog1.filename);
>                    end;
>                2 : begin
> DM.AssessmentsPhoto03.LoadFromFile(openDialog1.filename);
>                    end;
> .
> .
> .

>               29 : begin
> DM.AssessmentsPhoto30.LoadFromFile(openDialog1.filename);
>                    end;
>           end;

> I want to be able to do this in one statement if possible. The
> following compiles but gets an exception error when executed:

> TBlobField(FindComponent('DM.AssessmentsPhoto0'+IntToStr(Photo1Combo.ItemIndex+1))).LoadFromFile(openDialog1.filename);

> Can someone explain why and/or how to make this work please...

> Thanks in advance,

> Robbie...

Other Threads