gpt4 book ai didi

delphi - 在 DataModule 上使用函数

转载 作者:行者123 更新时间:2023-12-03 15:50:30 30 4
gpt4 key购买 nike

我有一个数据模块(TfDB),我想向其中添加此功能

 Function GetZone(zone :string):string;

当我尝试运行它时,出现此错误...外部声明的转发不满意:TfDB.GetZone

unit MyDataModule;

interface

uses
System.SysUtils, System.Classes, Data.DB, Data.Win.ADODB;

type
TfDB = class(TDataModule)
dbconnection: TADOConnection;
private
{ Private declarations }
public
Function GetZone(zone :string):string;
end;

var
fDB: TfDB;

implementation

{%CLASSGROUP 'System.Classes.TPersistent'}

{$R *.dfm}

Function GetZone(zone:string):string;
begin
if zone = 'FLayout1' then
result := '1';
if zone = 'FLayout2' then
result := '2';
if zone = 'FLayout3' then
result := '3';
if zone = 'FLayout4' then
result := '4' ;
if zone = 'FBoneYard' then
result := 'BoneYard';
if zone = 'FShop' then
result := 'shop';
if zone = 'FMisc' then
result := 'Misc' ;
end;

end.

最佳答案

在实现部分,您需要将函数声明为类的方法:

function TfDB.GetZone(zone:string):string;
begin
....
end;

您的声明如下所示:

function GetZone(zone:string):string;
begin
....
end;

这定义了一个独立的函数而不是类的方法。

关于delphi - 在 DataModule 上使用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14424240/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com