We help IT Professionals succeed at work.

code error

hugh34
hugh34 asked
on
Medium Priority
179 Views
Last Modified: 2010-04-06
can someone take a look at this code, as i cannot seem to get it to
work! I can compile it but when i click on an option button for
a relevant picture and click change, i get an error message saying "resource
not found". I know its someting to do with the "s : String" but i
cannot seem to figure it out!!!


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    opt1: TRadioButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    opt2: TRadioButton;
    opt3: TRadioButton;
    opt4: TRadioButton;
    btnChange: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnChangeClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  StartButton: hWnd;
  OldBitmap: THandle;
  NewImage: TPicture;


implementation

{$R *.DFM}
{$resource Pic.RES}

Procedure StartButtonBitmap( s : String);
begin
NewImage := TPicture.create;
NewImage.Bitmap.LoadFromResourceName(hInstance,'s');
StartButton := FindWindowEx
              (FindWindow(
                 'Shell_TrayWnd', nil),
                  0,'Button', nil);
OldBitmap := SendMessage(StartButton,
                        BM_SetImage, 0,
                        NewImage.Bitmap.Handle);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.Picture.Bitmap.LoadFromResourceName(hInstance,'PIC1');
Image2.Picture.Bitmap.LoadFromResourceName(hInstance,'PIC2');
Image3.Picture.Bitmap.LoadFromResourceName(hInstance,'PIC3');
Image4.Picture.Bitmap.LoadFromResourceName(hInstance,'PIC4');
end;

procedure TForm1.btnChangeClick(Sender: TObject);
begin
if opt1.checked = true then begin
StartButtonBitmap('PIC1') end else
if opt2.checked = true then
StartButtonBitmap('PIC2') else
if opt3.Checked = true then
StartButtonBitmap('PIC3')else
if opt4.Checked = true then
StartButtonBitmap('PIC4')
end;





end.
Comment
Watch Question

Commented:
Hi hugh34,

change you code :

implementation

{$R *.DFM}
{$resource Pic.RES}

Procedure StartButtonBitmap( s : String);
begin
NewImage := TPicture.create;
NewImage.Bitmap.LoadFromResourceName(hInstance,s);
....                                          ^^^

Best Regards

Cesario

Author

Commented:
thanx, it was so trivial, lol how come its always the minor errors i can never seem to debug!

thanks for your help Cesario

u r a credit to this site!!!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.