书上的一个例题函数是这样的
function TDragForm.AddNotDup (List: TCustomListBox; Text: string): Boolean;
begin
// 判断项目是否存在
Result := List.Items.IndexOf (Text) < 0;
if Result then
List.Items.Add (Text);
end;从函数中能看出来这个result应该是返回的值但是在我照着写的时候确报错
function tdragform.addnotdup(list:TCustomListBox;text:string):Boolean;
begin
Result:=list.
end;写到这里报错
[Pascal Error] Unit1.pas(1): Unable to invoke Code Completion due to errors in source code我想问书上的例题这个Result是从哪里出来的
function TDragForm.AddNotDup (List: TCustomListBox; Text: string): Boolean;
begin
// 判断项目是否存在
Result := List.Items.IndexOf (Text) < 0;
if Result then
List.Items.Add (Text);
end;从函数中能看出来这个result应该是返回的值但是在我照着写的时候确报错
function tdragform.addnotdup(list:TCustomListBox;text:string):Boolean;
begin
Result:=list.
end;写到这里报错
[Pascal Error] Unit1.pas(1): Unable to invoke Code Completion due to errors in source code我想问书上的例题这个Result是从哪里出来的
解决方案 »
- 想重装delphi,如何保存现delphi的所有第三方控件
- 数据类型转换 在线等
- 如何控制dbgrid的某一列的输入问题
- excelapplication1.ActiveWorkbook.SaveAs(savedialog2.FileName); 为什么总是提示参数不足?谢谢大侠!
- 有嗎? Delphi开发工程师.
- 请教:如何将当前窗体里某一个panel里的内容打印出来?最好能设置大小
- 调用vc dll问题——参数。
- 怎样取得DBGrid当前编辑行中的数据?
- quickReport的问题
- 一个研究生(我)的毕业设计——50RMB/MONTH
- 文件的内容用crc16效验了,如何通过文件内容知道效验码?
- vc转delphi问题
unit DragF;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls, CheckLst, ExtCtrls;type
TDragForm = class(TForm)
ListBox1: TListBox;
CheckListBox1: TCheckListBox;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
procedure ListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure CheckListBox1DragDrop(Sender, Source: TObject; X,
Y: Integer);
procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function AddNotDup (List: TCustomListBox; Text: string): Boolean;
end;var
DragForm: TDragForm;implementation{$R *.DFM}procedure TDragForm.ListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := True;
if (Source = Edit1) and
((Sender as TCustomListBox).Items.IndexOf (Edit1.Text) >= 0) then
Accept := False;
end;procedure TDragForm.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
I: Integer;
begin
if Source = Edit1 then
// 复制Edit控件中的文本
ListBox1.Items.Add (Edit1.Text)
else if Source = CheckListBox1 then
begin
// 复制所有选中的项目
// 删除选中的项目
for I := CheckListBox1.Items.Count - 1 downto 0 do
if CheckListBox1.Checked [I] then
begin
if AddNotDup (ListBox1, CheckListBox1.Items [I]) then
CheckListBox1.Items.Delete (I);
end;
end;
end;procedure TDragForm.CheckListBox1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
nItem: Integer;
begin
if Source = Edit1 then
// 复制Edit控件中的文本
CheckListBox1.Items.Add (Edit1.Text)
else if Source = ListBox1 then
begin
// 复制ListBox中被选中的项
nItem := ListBox1.ItemIndex;
if AddNotDup (CheckListBox1, ListBox1.Items [nItem]) then
// 删除被选中的项目
ListBox1.Items.Delete (nItem);
end;
end;procedure TDragForm.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit1.BeginDrag (False, 10);
end;function TDragForm.AddNotDup (List: TCustomListBox; Text: string): Boolean;
begin
// 判断项目是否存在
Result := List.Items.IndexOf (Text) < 0;
if Result then
List.Items.Add (Text);
end;procedure TDragForm.Button1Click(Sender: TObject);
//添加项目
begin
if not(edit1.Text='') then
ListBox1.items.Add(edit1.text);
end;end.
function tdragform.addnotdup(list:TCustomListBox;text:string):Boolean;
begin
Result:=list. //这里没写完
end;写到这里报错
[Pascal Error] Unit1.pas(1): Unable to invoke Code Completion due to errors in source code
函数的返回值是由函数定义决定的:function tdragform.addnotdup(list:TCustomListBox;text:string):Boolean;
Result的类型要和函数定义的类型一致
function tdragform.addnotdup(list:TCustomListBox;text:string):Boolean;
应该是Boolean类型
注意初始化
begin
Result:=list.//
end;写到这里报错注意红色的地方了么?