線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1626
推到 Plurk!
推到 Facebook!

TImage問題

尚未結案
rockmanexe45
一般會員


發表:1
回覆:0
積分:0
註冊:2010-03-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-03-05 22:27:04 IP:219.79.xxx.xxx 未訂閱
 我想在一個程式中讀取一個string作image.picture的地址,
要怎樣寫呢?麻煩大家了。
(該string是edit7.text)
unit CIT2;
interface
uses
Windows,Messages,SysUtils,Variants,Forms,Classes,Controls,Graphics,Dialogs,
Menus,ComCtrls,StdCtrls,ExtCtrls,ExtDlgs,ClipBrd,PNGimage,GIFimg, DBCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
ListBox1: TListBox;
ListView1: TListView;
StatusBar1: TStatusBar;
Edit8: TEdit;
Label8: TLabel;
Image1: TImage;
procedure New(Sender: TObject);
procedure Button1a(Sender: TObject);
procedure Button2a(Sender: TObject);
procedure Button3a(Sender: TObject);
procedure Button4a(Sender: TObject);
procedure Button5a(Sender: TObject);
procedure Button6a(Sender: TObject);
procedure Button7a(Sender: TObject);procedure Edit1keypress(Sender: TObject;var Key: Char);
procedure Edit2keypress(Sender: TObject; var Key: Char);
procedure Edit3keypress(Sender: TObject; var Key: Char);
procedure Edit4keypress(Sender: TObject; var Key: Char);
procedure Edit5keypress(Sender: TObject; var Key: Char);
procedure Edit6keypress(Sender: TObject; var Key: Char);
procedure Edit7keypress(Sender: TObject; var Key: Char);
procedure Edit8keypress(Sender: TObject; var Key: Char);
procedure Listbox1a(Sender: TObject);
procedure Listview1columnclick(Sender: TObject; Column: TListColumn);
procedure Listview1Compare(Sender: TObject; Item1, Item2: TListItem;Data: Integer; var Compare: Integer);
procedure Listview1selecteditem(Sender: TObject; Item: TListItem;Selected: Boolean);
procedure listview1keyup(Sender: TObject; var Key: Word;Shift: TShiftState);
procedure Edit3keydown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure addena(Sender: TObject);
procedure addpba(Sender: TObject);
procedure Searcha(Sender: TObject);
procedure Exit1a(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type info = RECORD
name,phone1,phone2,email,address,note,picture:string;
END;
var
Form1: TForm1;
pb:array of info;
cs: Integer;
no:integer;
filename,configname:string;
configfile:textfile;
implementation
{$R *.dfm}
procedure ShowMessage(const Msg, Title: string);
begin
MessageBox(Application.Handle, PChar(Msg), PChar(Title), MB_OK);
end;
function NtoID(n:integer):string;
var
outptstr:string;
begin
outptstr:=inttostr(n);
if length(outptstr)=3 then
NtoID:='0' outptstr
else
if length(outptstr)=2 then
NtoID:='00' outptstr
else
if length(outptstr)=1 then
NtoID:='000' outptstr
else
NtoID:=outptstr;
end;
procedure Loadphbk;
var
history:TextFile;
T:string;
S,n:integer;
begin
if filename<>'' then
begin
assignfile(history,filename);
{$I-}
reset(history);
{$I }
if IOResult=0 then
begin
readln(history,t);
if pos('[ephonebook]',t)=0 then
Showmessage('Cannot read Phonebook(Invaild list file)','Error')
else
begin
for n := 1 to no do
begin
pb[n].name:='';
end;
n:=0;
while not eof(history) do
begin
n:=n 1;
begin
readln(history,T);
S := Pos(#9,T);
pb[n].name := Copy(T,1,S-1);
Delete(T,1,S);
S := Pos(#9,T);
pb[n].phone1 := Copy(T,1,S-1);
Delete(T,1,S);
S := Pos(#9,T);
pb[n].phone2 := Copy(T,1,S-1);
Delete(T,1,S);
S := Pos(#9,T);
pb[n].email := Copy(T,1,S-1);
Delete(T,1,S);
S := Pos(#9,T);
pb[n].address := Copy(T,1,S-1);
Delete(T,1,S);
S := Pos(#9,T);
pb[n].note := Copy(T,1,S-1);
Delete(T,1,S);
pb[n].picture :=t;
end;
end;
closefile(history);
end;
end;
end;
end;
procedure TForm1.addpba(Sender: TObject);
begin
Button5a(sender)
end;
procedure TForm1.addena(Sender: TObject);
begin
Edit1.SetFocus();
end;
procedure TForm1.Searcha(Sender: TObject);
begin
combobox1.SetFocus();
Statusbar1.Panels[1].Text:='Please choose searching type.';
end;
procedure TForm1.Button1a(Sender: TObject);
var
name,phone1,phone2,email,address,note,picture,input:string;
listfile:TextFile;
begin
if filename<>''
then
if edit1.Text<>''
then
begin
Statusbar1.Panels[1].Text:='Adding New Entry';
name:=edit1.text;
phone1:=edit2.Text;
phone2:=edit3.Text;
email:=edit4.text;
address:=edit5.Text;
note:=edit6.text;
picture:=edit8.Text;
input:=(name ' ' email ' ' note ' ' picture);
assignfile(listfile,filename);
reset(listfile);
append(listfile);
writeln(listfile,input);
closefile(listfile);
Statusbar1.Panels[1].Text:='New Entry Added';
edit2.text:='';
edit3.text:='';
edit4.text:='';
edit5.text:='';
edit6.text:='';
edit7.text:='';
edit8.Text:='';
Button7a(sender);
end
else
showmessage('Please Select a Phonebook.','Error')
else
showmessage('Please Fill in the Informations.','Error');
end;
procedure TForm1.Button2a(Sender: TObject);
var
inputstr:string;
n:integer;
listfile:textfile;
begin
pb[n].name:= edit1.text;
pb[n].phone1:= edit2.text;
pb[n].phone2:= edit3.text;
pb[n].email:= edit4.text;
pb[n].address:= edit5.text;
pb[n].note:= edit6.text;
pb[n].picture:=edit8.Text;
Assignfile(listfile,filename);
reset(listfile);
rewrite(listfile);
writeln(listfile,'[ephonebook]');
for n:=1 to no do
begin
if pb[n].name<>'' then
begin
inputstr:=(pb[n].name ' ' pb[n].email ' ' pb[n].note ' ' pb[n].picture);
writeln(listfile,inputstr);
end;
end;
closefile(listfile);
Button7a(sender);
end;
procedure TForm1.Button3a(Sender: TObject);
var
inputstr:string;
n:integer;
listfile:textfile;
begin
if listview1.Selected<>nil then
IF MessageBox(HANDLE,'Remove this entry?','Warnning',MB_ICONINFORMATION or mb_yesno)=idyes THEN
begin
pb[n].name:='';
pb[n].phone1:='';
pb[n].phone2:='';
pb[n].email:='';
pb[n].address:='';
pb[n].note:='';
pb[n].picture:='';
Assignfile(listfile,filename);
rewrite(listfile);
writeln(listfile,'[ephonebook]');
for n:=1 to no do
begin
if pb[n].name<>'' then
begin
inputstr:=(pb[n].name ' ' pb[n].email ' ' pb[n].note ' ' pb[n].picture);
writeln(listfile,inputstr);
end;
end;
reset(listfile);
closefile(listfile);
Statusbar1.Panels[1].text:='Entry Removed';
Button7a(sender);
end;
end;
procedure TForm1.Button4a(Sender: TObject);
var
Item:TListItem;
p,n:integer;
entry:boolean;
begin
if edit7.text<>'' then
begin
entry:=false;
ListView1.Clear;
ListView1.items.Beginupdate;
if combobox1.text ='ID' then
begin
for n := 0001 to no do
begin
p :=pos(UpperCase(edit1.text),UpperCase (NtoID(n)));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
if (edit7.text>#47) and (edit7.text<#58) then
else
showmessage('Invalid input,ID must be 0-9','Error')
end;
if combobox1.text='Name' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].name));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
end;
if combobox1.text='Phone' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].phone1));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
if entry=false then
Statusbar1.Panels[1].Text:='Phonebooks not saved'
else
Statusbar1.Panels[1].Text:='Enter keyword of searching';
end;
if combobox1.text='Phone' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].phone2));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
if entry=false then
Statusbar1.Panels[1].Text:='Phonebooks not saved'
else
Statusbar1.Panels[1].Text:='Enter keyword of searching';
end;
if combobox1.text='E-mail' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].email));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
end;
if combobox1.text='Address' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].address));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
end;
if combobox1.text='Notes' then
begin
For n := 0001 to no do
begin
p := pos(UpperCase(edit1.text),UpperCase(pb[n].note));
if (p>0) then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
entry:=true;
end;
end;
end;
if entry=false then
begin
Statusbar1.Panels[1].Text:='Error'
end
else
Statusbar1.Panels[1].Text:='Enter keyword for searching';
ListView1.items.endupdate;
end
else
Button7a(Sender );
end;
procedure TForm1.Button5a(Sender: TObject);
var
t:string;
history:textfile;
begin
t:=inputbox('New Phonebook','Enter New Phonebook name','');
if t<>'' then
if (((t>#47) and (t<#58)) or ((t>#64) and (t<#91)) or ((t>#96) and (t<#123))) then
begin
assignfile(history,t);
{$I-}
reset(history);
{$I }
if IOResult=0 then
Showmessage('Phonebook exist already','Error')
else
begin
reset(configfile);
append(configfile);
writeln(configfile);
closefile(configfile);
rewrite(history);
writeln(history,'[ephonebook]');
listbox1.items.Add(t)
end;
closefile(history);
end
else
showmessage('Invaild File Name,file name must be 0-9,a-z,A-Z','Invalid Input')
end;
procedure TForm1.Button6a(Sender: TObject);
var
i,n:integer;
listfile:textfile;
phbks:array[0..500] of string;
begin
i:=0;
repeat
if listbox1.Selected[i]=true then
IF MessageBox(HANDLE,'Remove this phonebook?','Remove phonebook',MB_ICONINFORMATION or mb_yesno)=idyes THEN
begin
n:=0;
filename:=ListBox1.Items[ListBox1.ItemIndex];
listbox1.Items.Delete(i);
reset(configfile);
while not eof(configfile) do
begin
readln(configfile,phbks[n]);
n:=n 1;
end;
phbks[i]:='';
rewrite(configfile);
for n := 0 to 500 do
if phbks[n]<>'' then
writeln(configfile,phbks[n]);
closefile(configfile);
assignfile(listfile,filename);
erase(listfile);
end;
i:=i 1
until i=listbox1.count
end;
procedure TForm1.Button7a(Sender: TObject);
var
Item:tlistitem;
n:integer;
begin
ListView1.Clear;
ListView1.items.Beginupdate;
Statusbar1.Panels[1].Text:='Loading Phonebook';
Loadphbk;
for n := 1 to no do
if pb[n].name<>'' then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
end;
ListView1.items.EndUpdate;
Statusbar1.Panels[1].Text:='Phonebook loaded successfully';
end;
procedure TForm1.Listbox1a(Sender: TObject);
var i:integer;
begin
for i := 0 to Listbox1.Count-1 do
if listbox1.Selected[i]=true then
begin
filename:=ListBox1.Items[ListBox1.ItemIndex];
button7a(sender);
end;
end;
procedure TForm1.Listview1columnclick(Sender: TObject; Column: TListColumn);
begin
ListView1.SortType := stboth;
if listview1.Tag=1 then
listview1.Tag:=-1
else
listview1.Tag:=1;
cs := Column.Index;
(Sender as TCustomListView).AlphaSort;
ListView1.SortType := stNone;
end;
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
var
i: Integer;
begin
if cs = 0 then
if listview1.tag=1 then
Compare := CompareText(Item1.Caption,Item2.Caption)
else
Compare := CompareText(Item2.Caption,Item1.Caption)
else begin
i := cs - 1;
if listview1.Tag=1 then
Compare := CompareText(Item1.SubItems[i],Item2.SubItems[i])
else
Compare := CompareText(Item2.SubItems[i],Item1.SubItems[i]);
end;
end;
procedure TForm1.Listview1selecteditem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if Selected=true then
begin
edit1.text:=listview1.Selected.SubItems[0];
edit2.text:=listview1.Selected.SubItems[1];
edit3.text:=listview1.Selected.SubItems[2];
edit4.text:=listview1.Selected.SubItems[3];
edit5.text:=listview1.Selected.SubItems[4];
edit6.text:=listview1.Selected.SubItems[5];
button3.Enabled:=true;
button2.Enabled:=true;
end;
end;
procedure TForm1.listview1keyup(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key=46 then
if (ListView1.Selected <> nil ) then
Button3a(sender);
end;
procedure TForm1.New(Sender: TObject);
var
Item:TListItem;
n: integer;
listfile:textfile;
begin
combobox1.items.add('ID');
combobox1.items.add('Name');
combobox1.items.add('Phone');
combobox1.items.add('E-mail');
combobox1.items.add('Address');
combobox1.items.add('Notes');
combobox1.ItemIndex:=0;
ListView1.Clear;
configname:='pbcon1' ;
Assignfile(configfile,configname);
{$I-}
reset(configfile);
{$I }
if IOresult<>0 then
begin
filename:='Phonebook';
rewrite(configfile);
writeln(configfile,'PhoneBook');
listbox1.Items.Add(filename);
end
else
while not eof(configfile) do
begin
readln(configfile,filename);
listbox1.Items.Add(filename)
end;
closefile(configfile);
if filename<>'' then
begin
Assignfile(listfile,filename);
{$I-}
reset(listfile);
{$I }
if IOresult<>0 then
begin
rewrite(listfile);
writeln(listfile,'[ephonebook]')
end;
closefile(listfile);
end;
no:=5000;
setlength(pb,no);
Loadphbk;
for n := 1 to no do
if pb[n].name<>'' then
begin
Item := ListView1.Items.Add;
Item.Caption:=NtoID(n);
Item.subitems.Add(pb[n].name);
Item.SubItems.Add(pb[n].phone1);
Item.SubItems.Add(pb[n].phone2);
Item.SubItems.Add(pb[n].email);
Item.SubItems.Add(pb[n].address);
Item.SubItems.Add(pb[n].note);
end;
Statusbar1.Panels[1].Text:='Phonebook Loaded Successfully';
end;
procedure TForm1.Exit1a(Sender: TObject);
begin
IF MessageBox(HANDLE,'Are you sure to exit?','Exit Warnning',MB_ICONINFORMATION or mb_yesno)=idyes THEN
HALT(0);
end;
end.

編輯記錄
rockmanexe45 重新編輯於 2010-03-05 22:28:30, 註解 無‧
rockmanexe45 重新編輯於 2010-03-06 00:00:20, 註解 無‧
eaglewolf
資深會員


發表:4
回覆:268
積分:429
註冊:2006-07-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-03-06 10:07:55 IP:211.75.xxx.xxx 未訂閱
//請自行判斷 edit7.text為有效的圖檔名稱
Image1.Picture.LoadFromFile(edit7.Text);
------
先查HELP
再查GOOGLE
最後才發問

沒人有義務替你解答問題
在標題或文章中標明很急
並不會增加網友回答速度

Developing Tool:
1.Delphi 6
2.Visual Studio 2005
3.Visual Studio 2008
DBMS:
MS-SQL
Ktop_Robot
站務副站長


發表:0
回覆:3511
積分:0
註冊:2007-04-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-03-25 12:30:16 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-05-17 2:18:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!