Combox控件的问题,在线等待(30分)

  • 主题发起人 主题发起人 cjsh
  • 开始时间 开始时间
C

cjsh

Unregistered / Unconfirmed
GUEST, unregistred user!
我想继承Combox控件。
然后我想控件程序运行时候Combox.items的值从一个文本文件中得到
程序关闭时该文本文件的内容等于Combox.items的值
怎么做呀
我做的时候有一个问题,我是这样的做的,在控件的
constructor TUrlComboList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Items.LoadFromFile(ExtractFilePath(paramstr(0))+'Combotxt.txt');
end;

destructor TUrlComboList.Destroy;
begin
items.SavetoFile(ExtractFilePath(paramstr(0))+'Combotxt.txt');
inherited Destroy;
end;


完整代码如下:
unit UrlComboList;

interface

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

type
TUrlComboList = class(TComboBox)
private
{ Private declarations }
protected
{ Protected declarations }
//procedure SetParent(AParent: TWinControl); override;
procedure DblClick; override;
procedure Change; override;
procedure KeyPress(var Key: Char); override;
public
{ Public declarations }
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Standard', [TUrlComboList]);
end;

{ TUrlComboList }

procedure TUrlComboList.Change;
var
I,Len:integer;
Txt:String;
begin
inherited Change;
Txt:=text;
Len:=Length(txt);
if Len<=0 then exit;
for i:=0 to Items.Count-1 do
begin
if (txt)=(Items) then
begin
DroppedDown:=false;
exit;
end;
end;
DroppedDown:=true;
end;

constructor TUrlComboList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Items.LoadFromFile(ExtractFilePath(paramstr(0))+'Combotxt.txt');
end;

procedure TUrlComboList.DblClick;
begin
inherited DblClick;
DroppedDown:=true;
end;

destructor TUrlComboList.Destroy;
begin
items.SavetoFile(ExtractFilePath(paramstr(0))+'Combotxt.txt');
inherited Destroy;
end;

procedure TUrlComboList.KeyPress(var Key: Char);
var
i:integer;
begin
//inherited KeyPress(var Key);
if Length(Text)<=0 then exit;
i:=Items.IndexOf(Text);
if i<0 then
if key=#13 then
begin
Items.Add(Text);
end;
end;

{procedure TUrlComboList.SetParent(AParent: TWinControl);
begin
inherited SetParent(AParent);
end;}

end.


请各位帮我修改修改

 
什么问题?
 
procedure TUrlComboList.Change;
var
Len:integer;
Txt:String;
begin
inherited Change;
Txt:=text;
Len:=Length(txt);
if Len<=0 then exit;
if Items.Indexof(Txt)>=0 then
begin
DroppedDown:=False;
Exit;
end;
DroppedDown:=true;
end;


 

Similar threads

S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
S
回复
0
查看
888
SUNSTONE的Delphi笔记
S
I
回复
0
查看
567
import
I
后退
顶部