Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2010 Incompatible Types Error when compiling #4

Open
produdegr opened this issue Jan 24, 2025 · 1 comment
Open

E2010 Incompatible Types Error when compiling #4

produdegr opened this issue Jan 24, 2025 · 1 comment

Comments

@produdegr
Copy link

Hi and sorry for my ignorance, but I cant make it compile.
In the following code I allways get:
"[dcc32 Error] Unit8.pas(75): E2010 Incompatible types: 'System.SysUtils.TProc<System.TObject,Gemini.Chat.TChat>' and 'Procedure'"
Code:

" {--- Generate text from an image using its Uri. }
Gemini.Chat.AsynCreate('models/gemini-1.5-pro',
procedure (Params: TChatParams)
begin
Params.Contents([TPayload.Add('Describe this image.', [FileUri])]);
end,
function : TAsynChat
begin
Result.Sender := Memo1;
Result.OnSuccess := Display;
Result.OnError := Display;
end); "

Version: Embarcadero RAD Studio 12 Version 29.0.51961.7529

Did I forget something?
I declared " var Gemini := TGeminiFactory.CreateInstance('');" in my FormCreate.
My Units delaration in units section: "... , Gemini, Gemini.Models, Gemini.Chat, Gemini.Embeddings, Gemini.Safety, Gemini.Files;"

Thanks for your time.

@MaxiDonkey
Copy link
Owner

MaxiDonkey commented Jan 24, 2025

Hello,

It is crucial that the Display methods are correctly defined as follows:

For the OnSuccess event, the definition must be:

  • Display(Sender: TObject; Value: TChat);

If your Display method is declared with the following signature:

  • Display(Sender: TObject; const Value: TChat);
    you will encounter a compilation error stating: "incompatible types."

Therefore, ensure that the method is declared as:

  • Display(Sender: TObject; Value: TChat);

However, if you wish to keep your Display method with its current signature, you can use it as follows:

...
function TAsyncChat: TAsyncChat
begin
  Result.Sender := Memo1;
  Result.OnSuccess := 
    procedure(Sender: TObject; Value: TChat)
    begin
      Display(Sender, Value);
    end;
  …
end; 

Thus, you have two options to resolve this issue:

  1. Modify the Display method signature to match the expected definition.
  2. Adjust your code by wrapping the call to Display within an anonymous method.

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants