Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this not work????

Status
Not open for further replies.

cheesemunger

Programmer
Jul 6, 2007
11
ok, I have this code. It used to work but it now doesn't. After i put in the
Code:
  if  number = (1)or(2)or(3)or(4)or(5)or(6)or(7)       then
  begin
    imagename := 'Bullet' + IntToStr(number);
    Bullet := FindComponent( imageName ) as TImage;
  end;
  if number = 8 then
  begin
    imagename := 'Bullet' + '1';
    Bullet := FindComponent( imageName ) as TImage;
  end;

the whole code is here:

Thanks
 
I think this is
if number = (1)or(2)or(3)or(4)or(5)or(6)or(7) then
not a valid syntax.

if number in [1..7]

or

if (number>=1) and (number<=7)

or

if (number=1) or (number=2) or ...
 
Also assuming that you have declared 'bullet' correctly
and findcomponent will only work at the top level i.e if you have components that are children of others e.g a button on a panel then you must find the panel and then find the button within that.
and findcomponent wont return anything to indicate that it has failed so you should test to see you found component exists or you will get and exception if you try to access it. e.g.

Code:
  Panel := findcomponent('motor' + inttostr(Address));
   {test for nil return here to prevent crashes}
   if (panel <> nil) and (TPanel(Panel).enabled = False) then
      begin
         TPanel(Panel).enabled := true;
         with Panel do
             begin
                Button := findcomponent('Mpars' + inttostr(Address));

Steve [The sane]: Delphi a feersum engin indeed.
 
@Saggaunt : I don't understand what you are saying:( I don't know much about programming:(

@Otto: I have added what you said but it still doesn't work

I am getting the error:

Project1 raised exception class EActionViolation with message 'access violation at address 004517A3 in module 'Project1.exe'. Read address 00000040'.
 
have you declared your 'Bullet' TImage

Can you post a bit more of your code?

Code:
var Bullet: TImage;

To be honest I don't know if the syntax you have use will work. Images are 'harder' to work with, you may have to use assign. Make sure you look at the help files on TImage

Try declaring Bullet as TComponent

Code:
var Bullet: Tcomponent;

then do the cast

TImage(Bullet).(whatever property you want to access goes here) := etc;



Steve [The sane]: Delphi a feersum engin indeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top