Bosanac
asked on
change pictures (newbie...)
How am I to acomplish this (Just a beginner...):
Have some *.bmp pictures (in my exe folder- subfolder ...\Pictures) and change them in 7 second intervals and when clicked on (the picture) it goes hyperlink i.e triggers my default browser to specified adress that is linked to spec. picture???
Have some *.bmp pictures (in my exe folder- subfolder ...\Pictures) and change them in 7 second intervals and when clicked on (the picture) it goes hyperlink i.e triggers my default browser to specified adress that is linked to spec. picture???
In my example ive got 2 TButtons, and a TImage. One Button is to start the SlideShow style thing and the other is to stop it. If you want a delay of 7 secs then just change the line "Delay(1000);" to "Delay(7000);". I've created my own procedure to delay the change between pictures instead of just using "Sleep(7000);" because my procedure processes other Application Messages when a Delay is in process.
Also in my last procedure (Image1Click) you could get rid of the line if "S <> '' then" as it doesnt actually do anything.
Hello
I don't if you mean by the defualt broswers, but if you mean the defualt browers of the images, try this code
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Image1: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Path :string;
implementation
{$R *.DFM}
uses shellapi;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if ListBox1.Items.Count >= 0 then
begin
ListBox1.ItemIndex := ListBox1.ItemIndex + 1;
Image1.Picture.LoadFromFil e(Path + ListBox1.Items[ListBox1.It emIndex]);
if ListBox1.ItemIndex >= ListBox1.Items.Count -1 then
ListBox1.ItemIndex := -1;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
SearchRec: TSearchRec;
begin
Path := ExtractFilePath(Applicatio n.ExeName) + 'Picture\';
try
I := FindFirst(path+ '*.bmp', faAnyFile, SearchRec);
while I = 0 do
begin
listbox1.items.Add(SearchR ec.Name);
I := FindNext(SearchRec);
end;
FindClose(SearchRec);
except
raise;
end;
Timer1.Interval := 7000; // for 7 seconds
ListBox1.ItemIndex := -1;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
ShellExecute(handle, 'open',Pchar(Path + ListBox1.items[ListBox1.It emIndex]), nil,nil,sw _shownorma l);
end;
end.
I don't if you mean by the defualt broswers, but if you mean the defualt browers of the images, try this code
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Image1: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Path :string;
implementation
{$R *.DFM}
uses shellapi;
procedure TForm1.Timer1Timer(Sender:
begin
if ListBox1.Items.Count >= 0 then
begin
ListBox1.ItemIndex := ListBox1.ItemIndex + 1;
Image1.Picture.LoadFromFil
if ListBox1.ItemIndex >= ListBox1.Items.Count -1 then
ListBox1.ItemIndex := -1;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
SearchRec: TSearchRec;
begin
Path := ExtractFilePath(Applicatio
try
I := FindFirst(path+ '*.bmp', faAnyFile, SearchRec);
while I = 0 do
begin
listbox1.items.Add(SearchR
I := FindNext(SearchRec);
end;
FindClose(SearchRec);
except
raise;
end;
Timer1.Interval := 7000; // for 7 seconds
ListBox1.ItemIndex := -1;
end;
procedure TForm1.Image1Click(Sender:
begin
ShellExecute(handle, 'open',Pchar(Path + ListBox1.items[ListBox1.It
end;
end.
ASKER
Alan:
I have just compiled your example and something I do not understand here:
How do you know which picture is hyperlinked to which internet adress??
Example:
I have a banner (exchange.bmp) and is in my Pictures folder.Now when I click on it the hyperlink is supposed to take me to https://www.experts-exchange.com.
Now your app. loads random from my picture folder.How does it know the right h-link?There is danger also that user messes with order of pictures then I get all the wrong h-links...???
Also,when I click on the picture nothing happens.It is supposed to trigger my default browser and open the corresponding picture hyperlink....
MNAS...I mean triggering the default browser...
I have just compiled your example and something I do not understand here:
How do you know which picture is hyperlinked to which internet adress??
Example:
I have a banner (exchange.bmp) and is in my Pictures folder.Now when I click on it the hyperlink is supposed to take me to https://www.experts-exchange.com.
Now your app. loads random from my picture folder.How does it know the right h-link?There is danger also that user messes with order of pictures then I get all the wrong h-links...???
Also,when I click on the picture nothing happens.It is supposed to trigger my default browser and open the corresponding picture hyperlink....
MNAS...I mean triggering the default browser...
My code makes a list of the bmp's in a TStringList named StringList in my code. The list is obtained by some code which finds bmp files in the ../Pictures/ directory. When finding the bmp files, it finds them in Alpha-Numerical order and puts them in a list from the first one it finds to the last. The Interger, I, which is referred to in the Image1Click procedure is the position of the image when listed in the StringList (0 being first in the list). All you have to do is determine a list of all your bmp's in alpha-numerical order and then just list assign a url to the correct Integer position in the Image1Click procedure.
If you know what the images are called and they wont be changing names or anything then this would be better because the user wont beable to tamper around so easily.
If you know what the images are called and they wont be changing names or anything then this would be better because the user wont beable to tamper around so easily.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Why is it that when I click on an image my browser stays dead???
In my above example the images are defined in an array rather than being searched for. This will ensure that only the images with thoose names will be loaded. The array is the following line:
const
Pics : array[1..5] of string = ('exchange', 'delphi', 'test', 'global', 'hello');
If you look at the above code you'll see that the [1..5} indicates how many strings are in the array and defines an integer number for each string. In the Image1Click procedure you will see the code "case I of" and theen a list of numbers with a hyperlink... I have coded this so that the number in I corresponds to the position of the string in the array. For example when I is 1 it will mean 'exchange' in the array pics so i have made it load the hyperlink 'www.experts-exchange.com' and so on....
const
Pics : array[1..5] of string = ('exchange', 'delphi', 'test', 'global', 'hello');
If you look at the above code you'll see that the [1..5} indicates how many strings are in the array and defines an integer number for each string. In the Image1Click procedure you will see the code "case I of" and theen a list of numbers with a hyperlink... I have coded this so that the number in I corresponds to the position of the string in the array. For example when I is 1 it will mean 'exchange' in the array pics so i have made it load the hyperlink 'www.experts-exchange.com' and so on....
What browser and OS do you have???
if your images do NOT change then it might be best to put them in a .RES file and compile it with your app. You could just load the bmps from the resource and the user could not change them on disk.
ASKER
I use IE5.
I think that using resource would be a good idea...!
I shall first try sugg. above...
I think that using resource would be a good idea...!
I shall first try sugg. above...
My example finds all bmp's in the ../Pictures/ dir and shows them in the order found after building up a list of them.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ShellAPI;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Running : Boolean;
I : Integer;
implementation
{$R *.DFM}
procedure Delay(Ms : Longint);
var
TickCount : LongInt;
Msg : TMsg;
begin
TickCount := GetTickCount;
while GetTickCount - TickCount < Ms do
begin
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Could be set in Object Inspector
Button2.Enabled := False;
end;
procedure TForm1.Button1Click(Sender
var
SearchRec : TSearchRec;
StringList : TStringList;
begin
Running := True;
Button1.Enabled := False;
I := -1;
StringList := TStringList.Create;
FindFirst('Pictures\*.bmp'
StringList.Add(SearchRec.N
while FindNext(SearchRec) = 0 do
StringList.Add(SearchRec.N
FindClose(SearchRec);
Button2.Enabled := True;
while Running = True do
begin
Inc(I);
if I = StringList.Count then
I := 0;
Image1.Picture.LoadFromFil
Delay(1000); // Change to however many millisecs between image changes
end;
StringList.Free;
end;
procedure TForm1.Button2Click(Sender
begin
Running := False;
Button1.Enabled := True;
Button2.Enabled := False;
end;
procedure TForm1.Image1Click(Sender:
var
S : string;
begin
case I of
0: S := 'www.test1.com';
1: S := 'www.test2.com';
2: S := 'www.test3.com';
3: S := 'www.test4.com';
4: S := 'www.test5.com';
end;
if S <> '' then
ShellExecute(Handle, 'Open', PChar(S), nil, nil, SW_SHOWNORMAL);
end;
end.
Cheers,
Alan