In the main unit I have defined a function that is then called by another form with the appropriate parameter:
unit Parser;
interface
uses
[...]
function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
type
TForm1 = class(TForm)
[...]
function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
end;
[...]
function TForm1.SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
var
AStoreKey: string;
AOptions: TcxGridStorageOptions;
LayoutRegistryKey: TRegistry;
begin
AStoreKey := 'Software\KTRT\Stats';
AOptions := [];
cxGrid1TableView1.StoreToRegistry(AStoreKey, True, AOptions, ASaveViewName);
LayoutRegistryKey.RootKey:= HKEY_CURRENT_USER;
if LayoutRegistryKey.OpenKey(AStoreKey+'\'+ASaveViewName, false) then
Result := 0
else
Result := -1;
end;
In the other form:
[...]
uses Parser;
procedure TForm3.Button1Click(Sender: TObject);
var
LayoutRegistryKey: TRegistry;
AStoreLocation : AnsiString;
AStoreKey: string;
begin
AStoreLocation := Edit1.Text;
if Parser.SaveGridLayoutToReg(AStoreLocation) <> 0 then
Label1.Visible := True
else
begin
Label1.Visible := False;
Form3.Visible := False;
end;
end;
[...]
I am somehow doing it wrong since I keep getting the error
Unsatisfied forward or external declaration
If I don’t declare the function in the TForm1 class then the grid view won’t be found. If I don’t declare the function after the “uses” clause, I won’t be able to call it from the other form.
I really can’t get it 🙁
You declare two functions in the interface section, namely,
SaveGridLayoutToRegatand
TForm1.SaveGridLayoutToRega few lines later. But in the implementation section, you only implement the latter one.That is, you need to replace
with
or you have to implement both functions.