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

Demo project and OnGetQrCode parameters issues #91

Open
mbnoimi opened this issue Aug 13, 2024 · 33 comments
Open

Demo project and OnGetQrCode parameters issues #91

mbnoimi opened this issue Aug 13, 2024 · 33 comments

Comments

@mbnoimi
Copy link

mbnoimi commented Aug 13, 2024

Hi,

I'm building my first basic example but I couldn't figure out the correct parameters of OnGetQrCode.
I tried to use:

procedure(Sender: TObject; const QrCode: string; AImage: TBitmap)

but didn't work. May you please help me to fix it?

unit MaintForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  uTWPPConnect;

type
  TMainForm = class(TForm)
    btnSendMessage: TButton;
    edtPhoneNumber: TEdit;
    memoMessage: TMemo;
    lblStatus: TLabel;
    imgQrCode: TImage;
    procedure btnSendMessageClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    WPP: uTWPPConnect.TWPPConnect;
    procedure UpdateStatus(Status: string);
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  {$IFDEF CEFCurrentVersion}
  ShowMessage('CEFCurrentVersion is defined');
  {$ELSE}
  ShowMessage('CEFCurrentVersion is not defined');
  {$ENDIF}

  WPP := uTWPPConnect.TWPPConnect.Create(Self);

  //-----> [dcc32 Error] MaintForm.pas(48): E2009 Incompatible types: 'Parameter lists differ'
  WPP.OnGetQrCode := procedure(Sender: TObject; const QrCode: string; AImage: TBitmap)
  begin
    imgQrCode.Picture.Assign(AImage);
  end;

  UpdateStatus('Not Connected');
end;

procedure TMainForm.UpdateStatus(Status: string);
begin
  lblStatus.Caption := 'Status: ' + Status;
end;

procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
  TargetNumber, MessageText: string;
begin
  TargetNumber := edtPhoneNumber.Text + '@c.us';
  MessageText := memoMessage.Lines.Text;

  if WPP.Auth(True) then
  begin
    UpdateStatus('Connected');
    WPP.Send(TargetNumber, MessageText);
  end
  else
  begin
    UpdateStatus('Authentication required. Please scan the QR code.');
    ShowMessage('Authentication failed. Please scan the QR code.');
  end;
end;

end.
@DjotaHasse
Copy link
Contributor

OnGetQrCode is a component event.
First you must call the qrcode like this:

if not WPPWhats.Auth(false) then
begin
   WPPWhats.FormQrCodeType := TFormQrCodeType(Ft_None);
   WPPWhats.FormQrCodeStart;
end;

then in the onGetQrCode event the image will be returned:

procedure TFPrincipal2.WPPWhatsGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
begin
  imgQrCode.BeginUpdate;
  try
    imgQrCode.Bitmap := Base64ToBitmap(StrAfter(QrCode.AQrCode,'base64,'));
    sleep(500);
    imgQrCode.BringToFront;
    imgQrCode.Repaint;
  finally
    imgAguardeQrCode.Visible := imgQrCode.Bitmap.IsEmpty;
    lbAguardeQrCode.Visible  := imgQrCode.Bitmap.IsEmpty;
    AnimaAguardeQrCode.Stop;
    imgQrCode.EndUpdate;
  end;
end;

@mbnoimi
Copy link
Author

mbnoimi commented Aug 13, 2024

OnGetQrCode is a component event. First you must call the qrcode like this:

if not WPPWhats.Auth(false) then
begin
   WPPWhats.FormQrCodeType := TFormQrCodeType(Ft_None);
   WPPWhats.FormQrCodeStart;
end;

then in the onGetQrCode event the image will be returned:

procedure TFPrincipal2.WPPWhatsGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
begin
  imgQrCode.BeginUpdate;
  try
    imgQrCode.Bitmap := Base64ToBitmap(StrAfter(QrCode.AQrCode,'base64,'));
    sleep(500);
    imgQrCode.BringToFront;
    imgQrCode.Repaint;
  finally
    imgAguardeQrCode.Visible := imgQrCode.Bitmap.IsEmpty;
    lbAguardeQrCode.Visible  := imgQrCode.Bitmap.IsEmpty;
    AnimaAguardeQrCode.Stop;
    imgQrCode.EndUpdate;
  end;
end;

I couldn't understand much from your suggestion because I couldn't install WPP4Delphi design-time components (couldn't find any document for installation steps and Google translate didn't help me much).
For that the only option for me is trying to use it completely from the code (couldn't find suitable docs too for a quick start).

If I'm not wrong this suppose to get the benefit of component's event without the need to install it for design time.

  WPP.OnGetQrCode := procedure(Sender: TObject; const QrCode: string; AImage: TBitmap)
  begin
    imgQrCode.Picture.Assign(AImage);
  end;

But number of parameters is absolutely wrong.

So if you please try help me with my very basic example to be able run WPP4Delphi.

BTW, I couldn't run WPP4Delphi demo as well because it uses design-time components

@mbnoimi
Copy link
Author

mbnoimi commented Aug 13, 2024

@DjotaHasse I modified my code based on your suggestion (without understand it well) but I get these errors:

Checking project dependencies...
Compiling hpcwhatsapp.dproj (Debug, Win32)
dcc32 command line for "hpcwhatsapp.dpr"
  c:\program files (x86)\embarcadero\studio\23.0\bin\dcc32.exe -$O- -$W+ -$R+ -$Q+ --no-config -M -Q -TX.exe 
  -AGenerics.Collections=System.Generics.Collections;Generics.Defaults=System.Generics.Defaults;WinTypes=Winapi.Windows;WinProcs=Winapi.Windows;
  DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG;CEFCurrentVersion;;FRAMEWORK_VCL -E.\Win32\Debug -I"c:\program files 
  (x86)\embarcadero\studio\23.0\lib\Win32\debug";.\CEF4Delphi;.\CEF4Delphi\source;.\synapse;.\WPP4Delphi;.\WPP4Delphi\Source;.\WPP4Delphi\Source\JS;
  .\WPP4Delphi\Source\Model;.\WPP4Delphi\Source\Other;.\WPP4Delphi\Source\Services;.\WPP4Delphi\Source\View;.\WPP4Delphi\Packages\Compilados;
  .\WPP4Delphi\Packages\Compilados\VD29;"c:\program files (x86)\embarcadero\studio\23.0\lib\Win32\release";
  C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports;C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports\Win32;"c:\program 
  files (x86)\embarcadero\studio\23.0\Imports";C:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp;"c:\program files 
  (x86)\embarcadero\studio\23.0\include" -LEC:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl 
  -LNC:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp -NU.\Win32\Debug -NSWinapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;
  System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell; -O.\CEF4Delphi;.\CEF4Delphi\source;.\synapse;.\WPP4Delphi;
  .\WPP4Delphi\Source;.\WPP4Delphi\Source\JS;.\WPP4Delphi\Source\Model;.\WPP4Delphi\Source\Other;.\WPP4Delphi\Source\Services;.\WPP4Delphi\Source\View;
  .\WPP4Delphi\Packages\Compilados;.\WPP4Delphi\Packages\Compilados\VD29;"c:\program files (x86)\embarcadero\studio\23.0\lib\Win32\release";
  C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports;C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports\Win32;"c:\program 
  files (x86)\embarcadero\studio\23.0\Imports";C:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp;"c:\program files 
  (x86)\embarcadero\studio\23.0\include" -R.\CEF4Delphi;.\CEF4Delphi\source;.\synapse;.\WPP4Delphi;.\WPP4Delphi\Source;.\WPP4Delphi\Source\JS;
  .\WPP4Delphi\Source\Model;.\WPP4Delphi\Source\Other;.\WPP4Delphi\Source\Services;.\WPP4Delphi\Source\View;.\WPP4Delphi\Packages\Compilados;
  .\WPP4Delphi\Packages\Compilados\VD29;"c:\program files (x86)\embarcadero\studio\23.0\lib\Win32\release";
  C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports;C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports\Win32;"c:\program 
  files (x86)\embarcadero\studio\23.0\Imports";C:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp;"c:\program files 
  (x86)\embarcadero\studio\23.0\include" -U"c:\program files (x86)\embarcadero\studio\23.0\lib\Win32\debug";.\CEF4Delphi;.\CEF4Delphi\source;.\synapse;
  .\WPP4Delphi;.\WPP4Delphi\Source;.\WPP4Delphi\Source\JS;.\WPP4Delphi\Source\Model;.\WPP4Delphi\Source\Other;.\WPP4Delphi\Source\Services;
  .\WPP4Delphi\Source\View;.\WPP4Delphi\Packages\Compilados;.\WPP4Delphi\Packages\Compilados\VD29;"c:\program files 
  (x86)\embarcadero\studio\23.0\lib\Win32\release";C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports;
  C:\Users\Administrator\Documents\Embarcadero\Studio\23.0\Imports\Win32;"c:\program files (x86)\embarcadero\studio\23.0\Imports";
  C:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp;"c:\program files (x86)\embarcadero\studio\23.0\include" -V -VN 
  -NBC:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp -NHC:\Users\Public\Documents\Embarcadero\Studio\23.0\hpp\Win32 -NO.\Win32\Debug  
  hpcwhatsapp.dpr   
[dcc32 Error] MaintForm.pas(58): E2003 Undeclared identifier: 'BeginUpdate'
[dcc32 Error] MaintForm.pas(60): E2003 Undeclared identifier: 'Bitmap'
[dcc32 Error] MaintForm.pas(60): E2003 Undeclared identifier: 'StrAfter'
[dcc32 Error] MaintForm.pas(68): E2003 Undeclared identifier: 'EndUpdate'
[dcc32 Error] MaintForm.pas(70): E2010 Incompatible types: 'TOnGetQrCode' and 'Procedure'
[dcc32 Warning] MaintForm.pas(90): W1000 Symbol 'Send' is deprecated
[dcc32 Fatal Error] hpcwhatsapp.dpr(5): F2063 Could not compile used unit 'MaintForm.pas'
Failed
Elapsed time: 00:00:03.8

This is my modified code:

unit MaintForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
//   WPP4Delphi units
  uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
  uWPPConnectDecryptFile, JsonDataObjects,
  uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
  uTWPPConnect.Config, uTWPPConnect.Classes,
  uTWPPConnect.Emoticons;

type
  TMainForm = class(TForm)
    btnSendMessage: TButton;
    edtPhoneNumber: TEdit;
    memoMessage: TMemo;
    lblStatus: TLabel;
    imgQrCode: TImage;
    procedure btnSendMessageClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    WPP: uTWPPConnect.TWPPConnect;
    procedure UpdateStatus(Status: string);
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  {$IFDEF CEFCurrentVersion}
  ShowMessage('CEFCurrentVersion is defined');
  {$ELSE}
  ShowMessage('CEFCurrentVersion is not defined');
  {$ENDIF}

  WPP := uTWPPConnect.TWPPConnect.Create(Self);

  if not WPP.Auth(false) then
  begin
     WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
     WPP.FormQrCodeStart;
  end;

  WPP.OnGetQrCode := procedure(const Sender: TObject; const QrCode: TResultQRCodeClass)
  begin
//    imgQrCode.Picture.Assign(AImage);
    imgQrCode.BeginUpdate;
    try
      imgQrCode.Bitmap := Base64ToBitmap(StrAfter(QrCode.AQrCode,'base64,'));
      sleep(500);
      imgQrCode.BringToFront;
      imgQrCode.Repaint;
    finally
//      imgAguardeQrCode.Visible := imgQrCode.Bitmap.IsEmpty;
//      lbAguardeQrCode.Visible  := imgQrCode.Bitmap.IsEmpty;
//      AnimaAguardeQrCode.Stop;
      imgQrCode.EndUpdate;
    end;
  end;

  UpdateStatus('Not Connected');
end;

procedure TMainForm.UpdateStatus(Status: string);
begin
  lblStatus.Caption := 'Status: ' + Status;
end;

procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
  TargetNumber, MessageText: string;
begin
  TargetNumber := edtPhoneNumber.Text + '@c.us';
  MessageText := memoMessage.Lines.Text;

  if WPP.Auth(True) then
  begin
    UpdateStatus('Connected');
    WPP.Send(TargetNumber, MessageText);
  end
  else
  begin
    UpdateStatus('Authentication required. Please scan the QR code.');
    ShowMessage('Authentication failed. Please scan the QR code.');
  end;
end;

end.

@mbnoimi
Copy link
Author

mbnoimi commented Aug 13, 2024

I tried something silly too. I implemented Base64ToBitmap manually as I don't know the used unit in your suggestion but this lead to a new runtime error (didn't understand it):

image

unit MaintForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
  uWPPConnectDecryptFile, JsonDataObjects,
  uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
  uTWPPConnect.Config, uTWPPConnect.Classes,
  uTWPPConnect.Emoticons, System.NetEncoding;

type
  TMainForm = class(TForm)
    btnSendMessage: TButton;
    edtPhoneNumber: TEdit;
    memoMessage: TMemo;
    lblStatus: TLabel;
    imgQrCode: TImage;
    procedure btnSendMessageClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure WPPGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
    function Base64ToBitmap(const Base64: string): TBitmap;
  private
    { Private declarations }
    WPP: uTWPPConnect.TWPPConnect;
    procedure UpdateStatus(Status: string);
    function ExtractBase64(const Input: string): string;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  {$IFDEF CEFCurrentVersion}
  ShowMessage('CEFCurrentVersion is defined');
  {$ELSE}
  ShowMessage('CEFCurrentVersion is not defined');
  {$ENDIF}
end;

procedure TMainForm.WPPGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
begin
  imgQrCode.Picture.Bitmap.Canvas.Lock;
  try
    imgQrCode.Picture.Bitmap := Base64ToBitmap(ExtractBase64(QrCode.AQrCode));
    Sleep(500);
    imgQrCode.BringToFront;
    imgQrCode.Repaint;
  finally
    imgQrCode.Picture.Bitmap.Canvas.Unlock;
  end;
end;

function TMainForm.Base64ToBitmap(const Base64: string): TBitmap;
var
  InputStream: TStringStream;
  OutputStream: TMemoryStream;
begin
  Result := TBitmap.Create;
  InputStream := TStringStream.Create(Base64);
  OutputStream := TMemoryStream.Create;
  try
    TNetEncoding.Base64.Decode(InputStream, OutputStream);
    OutputStream.Position := 0;
    Result.LoadFromStream(OutputStream);
  finally
    InputStream.Free;
    OutputStream.Free;
  end;
end;

procedure TMainForm.UpdateStatus(Status: string);
begin
  lblStatus.Caption := 'Status: ' + Status;
end;

procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
  TargetNumber, MessageText: string;
begin
//                             ShowMessage('hi');
 WPP := uTWPPConnect.TWPPConnect.Create(Self);

  if not WPP.Auth(false) then
  begin
    WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
    WPP.FormQrCodeStart;
  end;

  WPP.OnGetQrCode := WPPGetQrCode;

  UpdateStatus('Not Connected');

  TargetNumber := edtPhoneNumber.Text + '@c.us';
  MessageText := memoMessage.Lines.Text;

  if WPP.Auth(True) then
  begin
    UpdateStatus('Connected');
    WPP.Send(TargetNumber, MessageText);
  end
  else
  begin
    UpdateStatus('Authentication required. Please scan the QR code.');
    ShowMessage('Authentication failed. Please scan the QR code.');
  end;
end;

function TMainForm.ExtractBase64(const Input: string): string;
begin
  Result := Copy(Input, Pos('base64,', Input) + 7, Length(Input));
end;

end.

@DjotaHasse
Copy link
Contributor

In Project >> View Sorce, add:

if not GlobalCEFApp.StartMainProcess then
    Exit;

@mbnoimi
Copy link
Author

mbnoimi commented Aug 14, 2024

In Project >> View Sorce, add:

Where can I find this config?

image

@DjotaHasse
Copy link
Contributor

It's not inside options, it's Project >> View Source

@mbnoimi
Copy link
Author

mbnoimi commented Aug 14, 2024

Thanks.
Got another runtime error message:
image

OnGetQrCode to be defined in this procedure!
What's wrong?

procedure TMainForm.WPPGetQrCode(const Sender: TObject; const QrCode: TResultQRCodeClass);
begin
  imgQrCode.Picture.Bitmap.Canvas.Lock;
  try
    imgQrCode.Picture.Bitmap := Base64ToBitmap(ExtractBase64(QrCode.AQrCode));
    Sleep(500);
    imgQrCode.BringToFront;
    imgQrCode.Repaint;
  finally
    imgQrCode.Picture.Bitmap.Canvas.Unlock;
  end;
end;

@DjotaHasse
Copy link
Contributor

Create the component and set OnGetQrcode in the create form to test

@mbnoimi
Copy link
Author

mbnoimi commented Sep 15, 2024

I wonder why you closed this issue while it related to #92 ?!
I'm still unable to use WPP4Delphi properly because I'm still unable to install any component!

@marcelo386 marcelo386 reopened this Sep 15, 2024
@marcelo386
Copy link
Collaborator

I reopened this issue, give more details than you need, it seems to me that you are not using it in the traditional way, you are creating in run time, adding and taking parts of the component, for this I will tag someone who is using it this way, which is a little different from the use of most developers, who use the component
@ThiagoPedro

@mbnoimi
Copy link
Author

mbnoimi commented Sep 16, 2024

Create the component and set OnGetQrcode in the create form to test

Did it (I finally became able to install WPP4Delphi).
I still get the same error message OnGetQrCode não foi definido

here is my recent modification:

unit MaintForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  JsonDataObjects, System.NetEncoding,
  uTWPPConnect.ConfigCEF, uTWPPConnect, uTWPPConnect.Constant, uTWPPConnect.JS,
  uWPPConnectDecryptFile,
  uTWPPConnect.Console, uTWPPConnect.Diversos, uTWPPConnect.AdjustNumber,
  uTWPPConnect.Config, uTWPPConnect.Classes,
  uTWPPConnect.Emoticons;

type
  TMainForm = class(TForm)
    btnSendMessage: TButton;
    edtPhoneNumber: TEdit;
    memoMessage: TMemo;
    lblStatus: TLabel;
    imgQrCode: TImage;
    WPP: TWPPConnect;
    procedure btnSendMessageClick(Sender: TObject);
    function Base64ToBitmap(const Base64: string): TBitmap;
    procedure WPPGetQrCode(const Sender: TObject;
      const QrCode: TResultQRCodeClass);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure UpdateStatus(Status: string);
    function ExtractBase64(const Input: string): string;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

function TMainForm.Base64ToBitmap(const Base64: string): TBitmap;
var
  InputStream: TStringStream;
  OutputStream: TMemoryStream;
begin
  Result := TBitmap.Create;
  InputStream := TStringStream.Create(Base64);
  OutputStream := TMemoryStream.Create;
  try
    TNetEncoding.Base64.Decode(InputStream, OutputStream);
    OutputStream.Position := 0;
    Result.LoadFromStream(OutputStream);
  finally
    InputStream.Free;
    OutputStream.Free;
  end;
end;

procedure TMainForm.UpdateStatus(Status: string);
begin
  lblStatus.Caption := 'Status: ' + Status;
end;

procedure TMainForm.WPPGetQrCode(const Sender: TObject;
  const QrCode: TResultQRCodeClass);
begin
  imgQrCode.Picture.Bitmap.Canvas.Lock;
  try
    imgQrCode.Picture.Bitmap := Base64ToBitmap(ExtractBase64(QrCode.AQrCode));
    Sleep(500);
    imgQrCode.BringToFront;
    imgQrCode.Repaint;
  finally
    imgQrCode.Picture.Bitmap.Canvas.Unlock;
  end;
end;

procedure TMainForm.btnSendMessageClick(Sender: TObject);
var
  TargetNumber, MessageText: string;
begin
  if not Assigned(WPP) then
    WPP := TWPPConnect.Create(Self);  // Ensure the WPP instance is created

  if not WPP.Auth(false) then
  begin
    WPP.FormQrCodeType := TFormQrCodeType(Ft_None);
    WPP.FormQrCodeStart();
  end;

  UpdateStatus('Not Connected');
  TargetNumber := edtPhoneNumber.Text + '@c.us';
  MessageText := memoMessage.Lines.Text;

  if WPP.Auth(True) then
  begin
    UpdateStatus('Connected');
    WPP.Send(TargetNumber, MessageText);
  end
  else
  begin
    UpdateStatus('Authentication required. Please scan the QR code.');
    ShowMessage('Authentication failed. Please scan the QR code.');
  end;
end;


function TMainForm.ExtractBase64(const Input: string): string;
begin
  Result := Copy(Input, Pos('base64,', Input) + 7, Length(Input));
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  WPP.OnGetQrCode := WPPGetQrCode;
end;

end.

You can find the full project here: SimpleDemo.zip

@mbnoimi
Copy link
Author

mbnoimi commented Sep 16, 2024

@DjotaHasse as you can see in MaintForm.dfm the component event is already defined.

object WPP: TWPPConnect
    InjectJS.AutoUpdateTimeOut = 10
    InjectJS.JSURL = 
      'https://raw.githubusercontent.com/wppconnect-team/WPP4Delphi/mai' +
      'n/Source/JS/js.abr'
    InjectJS.DownloadJSType = DT_Indy
    Config.AutoDelay = 1000
    AjustNumber.LengthPhone = 8
    AjustNumber.DDIDefault = 55
    FormQrCodeType = Ft_Http
    OnGetQrCode = WPPGetQrCode
    Left = 304
    Top = 224
  end

@DjotaHasse
Copy link
Contributor

If you placed the component on the screen, it doesn't make sense for you to create the event at run time, click on the component, press F11, go to the events tab, double click on OnGetQrCode and that's it, problem solved.

@DjotaHasse
Copy link
Contributor

Another thing, the component has a demo folder with a project that is used as an operating parameter for devs who are starting to use it, run this demo and see if it works correctly.

@mbnoimi
Copy link
Author

mbnoimi commented Sep 16, 2024

If you placed the component on the screen, it doesn't make sense for you to create the event at run time, click on the component, press F11, go to the events tab, double click on OnGetQrCode and that's it, problem solved.

I already did as I quoted from MaintForm.dfm

image

BTW, I attached the simple project. May you please take a look into it?

@DjotaHasse
Copy link
Contributor

If you created the event directly through the component, you don't need to set the event at run time, remove this from your project:
procedure TMainForm.FormCreate(Sender: TObject); begin WPP.OnGetQrCode := WPPGetQrCode; end;

@mbnoimi
Copy link
Author

mbnoimi commented Sep 16, 2024

Another thing, the component has a demo folder with a project that is used as an operating parameter for devs who are starting to use it, run this demo and see if it works correctly.

Crashes for unknown reason although I put all the dependencies in C:\Executaveis\WPPConnectDemo

image

image

image

ConfTWPPConnect.ini

[Path Defines]
Data User=C:\Executaveis\WPPConnectDemo\User Data
FrameWork=C:\Executaveis\WPPConnectDemo
Binary=C:\Executaveis\WPPConnectDemo
Locales=C:\Executaveis\WPPConnectDemo\locales
Cache=C:\Executaveis\WPPConnectDemo\cache
Log File=C:\Executaveis\WPPConnectDemo\LogTWppConnect\
Log Console=C:\Executaveis\WPPConnectDemo\LogTWppConnect\
GPU=1
Log Severity=0
Log Console Active=0
language=pt-BR
Auto Receiver attached=0
[TWPPConnect Comp]
TWPPConnect Versão=3.9.0.0
Caminho JS=https://raw.githubusercontent.com/wppconnect-team/WPP4Delphi/main/Source/JS/js.abr
CEF4 Versão=109.1.18.0
CHROME Versão=109.0.5414.120
Dlls=libcef.dll / chrome_elf.dll
Ultima interação=16/09/24 05:08:26
[Config]
AcceptLanguageList=pt-BR,pt-BR;q=0.9,en-US;q=0.8,en;q=0.7
SecondsMonitor=
SecondsMonitorNew=
Evento_msg_ack_change=
Evento_msg_revoke=
Evento_new_message=
Evento_new_reaction=
Evento_active_chat=
Evento_update_label=
Evento_presence_change=
Evento_group_participant_changed=
Evento_live_location_start=
Evento_order_payment_status=
[Informacao]
Aplicativo vinculado=C:\Executaveis\WPPConnectDemo\WPPConnectDemo.exe
Valor True=1
Valor False=0

The runtime files copied from:

  • cef_binary_109.1.18+gf1c41e4+chromium-109.0.5414.120_windows32\Debug
  • cef_binary_109.1.18+gf1c41e4+chromium-109.0.5414.120_windows32\Resources
  • WPP4Delphi\Demo\DLL's\dlls para Could not load SSL library.zip

@DjotaHasse
Copy link
Contributor

Delete this file ini and recopile the project.

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

Delete this file ini and recopile the project.

Got this runtime error:

First chance exception at $765BFA72. Exception class EIdOSSLUnderlyingCryptoError with message
'Error connecting with SSL.
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version'.
Process WPPConnectDemo.exe (6772)

image

image

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

I belive this issue related to an old OpenSSL binaries. It seems WPP4Delphi uses OpenSSL 1.x.x while the valid one is 1.1.x or 3.x.x
So I tried to use openssl-1.1.1w-win32 but WPP4Delphi demo project didn't accept it! After 1 hrs googling I figured out that:

OpenSSL version 1.1.x no longer uses the libeay32.dll and ssleay32.dll files. These were replaced in OpenSSL 1.1.x with the following:

  • libcrypto-1_1.dll (replaces libeay32.dll)
  • libssl-1_1.dll (replaces ssleay32.dll)

How this demo runs in your machines while it uses deprecated ssl binaries?!

@mbnoimi mbnoimi changed the title Determine OnGetQrCode parameters Demo project and OnGetQrCode parameters issues Sep 17, 2024
@DjotaHasse
Copy link
Contributor

Inside the component folder there is a folder with the openssl dlls, or you can go to the component properties, InjectJS - DownloadJSType and change it to DT_Rest

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

Inside the component folder there is a folder with the openssl dlls,

There is no such folder in project tree (DEMO or WPP4Delphi)

or you can go to the component properties, InjectJS - DownloadJSType and change it to DT_Rest

Did it. still get a runtime error!

image

@DjotaHasse
Copy link
Contributor

DjotaHasse commented Sep 17, 2024

There is no such folder in project tree (DEMO or WPP4Delphi)

Inside the DEMO folder there is the DLLs subfolder

Did it. still get a runtime error!

What error occurs?

This error is occurring when downloading the updated js.abr file. This error may also be occurring due to an operating system problem, it is important that it is updated to update the TLS protocol, this error is no longer due to the component.

@DjotaHasse
Copy link
Contributor

To overcome this error, in the InjectJS - AutoUpdate component property, change it from true to false so that the component will not try to download the js file, but this file always changes because it contains the js commands that are injected into the CEF for operation of the component, if it becomes very outdated, some commands stop working and you will have to update this file manually in your project folder.

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

Inside the DEMO folder there is the DLLs subfolder

I mentioned before that I used these dlls.

WPP4Delphi\Demo\DLL's\dlls para Could not load SSL library.zip

What error occurs?

a runtime error. I couldn't capture its details. Below a screenshot after run with debug
image

This error is occurring when downloading the updated js.abr file. This error may also be occurring due to an operating system problem, it is important that it is updated to update the TLS protocol, this error is no longer due to the component.

There is no way this issue related to my operating system because Chrome works fine with Web Whatsapp.

To overcome this error, in the InjectJS - AutoUpdate component property, change it from true to false so that the component will not try to download the js file

Tried it. Nothing changed! The demo still crashes

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

image

@DjotaHasse
Copy link
Contributor

It's not because your Chrome opens webwhats that the component has the same behavior, the component uses a Chromium engine.
And this error has nothing to do with Chrome, it's happening because it's not being able to download the js file as I mentioned. We have a WhatsApp group with more than 500 members using the component. This error that you are experiencing is a problem in Indy with openssl dlls, so just search on Google to find a solution.

@DjotaHasse
Copy link
Contributor

It could be a firewall, antivirus, something on your network that could block this as well

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

just search on Google to find a solution.

This project has a tiny community so there are no useful result on Google. I Googled a lot before asking my question and if you noticed this issue published since a while which means I reach to a dead end.

@DjotaHasse
Copy link
Contributor

did you add libeay32.dll and ssleay32.dll in your project's exe folder?

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

did you add libeay32.dll and ssleay32.dll in your project's exe folder?

Sure. I mentioned that before.

@mbnoimi
Copy link
Author

mbnoimi commented Sep 17, 2024

It could be a firewall, antivirus, something on your network that could block this as well

Everything is disabled. I even successfully downloaded js manually using my Chrome browser.
https://raw.githubusercontent.com/wppconnect-team/WPP4Delphi/main/Source/JS/js.abr

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

3 participants