delphi自定义函数添加 10
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ComCtrls, ExtCtrls, DBCtrls, Mask, DB,
ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
GroupBox1: TGroupBox;
DBGrid1: TDBGrid;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBComboBox1: TDBComboBox;
Label3: TLabel;
DBComboBox2: TDBComboBox;
Label4: TLabel;
DBEdit2: TDBEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
GroupBox2: TGroupBox;
Label5: TLabel;
Edit1: TEdit;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DataSource3: TDataSource;
DataSource4: TDataSource;
ComboBox1: TComboBox;
Label6: TLabel;
ADOConnection1: TADOConnection;
ADODataSet2: TADODataSet;
Label7: TLabel;
ComboBox2: TComboBox;
ADODataSet3: TADODataSet;
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
fuction GetIDByName(name:string;table:string):string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{TForm1}
//根据名称得到编码函数
fuction TForm1.GetIDByName(name:string;table:string):string;
begin
ADODataSet2.Active:=false;
ADODataSet2.CommandText:='select id from'+table+'where name='''+name+'''';
ADODataSet2.Active:=true;
if not(ADODataSet2.IsEmpty)then
begin
GetIDByName:=ADODataSet2.FieldByName('id').AsString;
end
else
begin
Application.MessageBox('没有找到对应的编码!','错误',MB_OK);
end;
end;
我就想做一个根据名称得到编码的函数,本人初学者,请高手指点为什么会出现很多错误,哪错了捏?函数运行好了,我还要在调用它呢~谢了 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ComCtrls, ExtCtrls, DBCtrls, Mask, DB,
ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
GroupBox1: TGroupBox;
DBGrid1: TDBGrid;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBComboBox1: TDBComboBox;
Label3: TLabel;
DBComboBox2: TDBComboBox;
Label4: TLabel;
DBEdit2: TDBEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
GroupBox2: TGroupBox;
Label5: TLabel;
Edit1: TEdit;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DataSource3: TDataSource;
DataSource4: TDataSource;
ComboBox1: TComboBox;
Label6: TLabel;
ADOConnection1: TADOConnection;
ADODataSet2: TADODataSet;
Label7: TLabel;
ComboBox2: TComboBox;
ADODataSet3: TADODataSet;
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
fuction GetIDByName(name:string;table:string):string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{TForm1}
//根据名称得到编码函数
fuction TForm1.GetIDByName(name:string;table:string):string;
begin
ADODataSet2.Active:=false;
ADODataSet2.CommandText:='select id from'+table+'where name='''+name+'''';
ADODataSet2.Active:=true;
if not(ADODataSet2.IsEmpty)then
begin
GetIDByName:=ADODataSet2.FieldByName('id').AsString;
end
else
begin
Application.MessageBox('没有找到对应的编码!','错误',MB_OK);
end;
end;
我就想做一个根据名称得到编码的函数,本人初学者,请高手指点为什么会出现很多错误,哪错了捏?函数运行好了,我还要在调用它呢~谢了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询