unit Chilkat.Dh;

{
  Pascal wrapper for Chilkat Dh.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TDh wraps CkDh via the C bridge layer. }
  TDh = class(TChilkatBase)
  private
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetG: Integer;
    function  GetP: string;
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property G: Integer read GetG;
    property P: string read GetP;

    function  CreateE(numBits: Integer): string;
    function  FindK(const E: string): string;
    function  GenPG(numBits: Integer; G: Integer): Boolean;
    function  SetPG(const p: string; g: Integer): Boolean;
    procedure UseKnownPrime(index: Integer);
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkDh_Create  = function(): Pointer; cdecl;
  TCkDh_Dispose = procedure(handle: Pointer); cdecl;
  TCkDh_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkDh_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkDh_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkDh_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkDh_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkDh_get_G = function(handle: Pointer): Integer; cdecl;
  TCkDh_get_P = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDh_CreateE = function(handle: Pointer; numBits: Integer): PAnsiChar; cdecl;
  TCkDh_FindK = function(handle: Pointer; E: PAnsiChar): PAnsiChar; cdecl;
  TCkDh_GenPG = function(handle: Pointer; numBits: Integer; G: Integer): LongBool; cdecl;
  TCkDh_SetPG = function(handle: Pointer; p: PAnsiChar; g: Integer): LongBool; cdecl;
  TCkDh_UseKnownPrime = procedure(handle: Pointer; index: Integer); cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkDh_Create:  TCkDh_Create  = nil;
  CkDh_Dispose: TCkDh_Dispose = nil;
  CkDh_get_LastErrorHtml: TCkDh_get_LastErrorHtml = nil;
  CkDh_get_LastErrorText: TCkDh_get_LastErrorText = nil;
  CkDh_get_LastErrorXml: TCkDh_get_LastErrorXml = nil;
  CkDh_get_Version: TCkDh_get_Version = nil;
  CkDh_get_DebugLogFilePath: TCkDh_get_DebugLogFilePath = nil;
  CkDh_put_DebugLogFilePath: TCkDh_put_DebugLogFilePath = nil;
  CkDh_get_VerboseLogging: TCkDh_get_VerboseLogging = nil;
  CkDh_put_VerboseLogging: TCkDh_put_VerboseLogging = nil;
  CkDh_get_LastMethodSuccess: TCkDh_get_LastMethodSuccess = nil;
  CkDh_put_LastMethodSuccess: TCkDh_put_LastMethodSuccess = nil;
  CkDh_get_G: TCkDh_get_G = nil;
  CkDh_get_P: TCkDh_get_P = nil;
  CkDh_CreateE: TCkDh_CreateE = nil;
  CkDh_FindK: TCkDh_FindK = nil;
  CkDh_GenPG: TCkDh_GenPG = nil;
  CkDh_SetPG: TCkDh_SetPG = nil;
  CkDh_UseKnownPrime: TCkDh_UseKnownPrime = nil;

constructor TDh.Create;
begin
  inherited Create;
  FHandle := CkDh_Create();
end;

destructor TDh.Destroy;
begin
  if FHandle <> nil then
    CkDh_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

function TDh.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkDh_get_LastErrorHtml(FHandle));
end;

function TDh.GetLastErrorText: string;
begin
  Result := CkToStr(CkDh_get_LastErrorText(FHandle));
end;

function TDh.GetLastErrorXml: string;
begin
  Result := CkToStr(CkDh_get_LastErrorXml(FHandle));
end;

function TDh.GetVersion: string;
begin
  Result := CkToStr(CkDh_get_Version(FHandle));
end;

function TDh.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkDh_get_DebugLogFilePath(FHandle));
end;

procedure TDh.SetDebugLogFilePath(AValue: string);
begin
  CkDh_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TDh.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkDh_get_VerboseLogging(FHandle));
end;

procedure TDh.SetVerboseLogging(AValue: Boolean);
begin
  CkDh_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TDh.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkDh_get_LastMethodSuccess(FHandle));
end;

procedure TDh.SetLastMethodSuccess(AValue: Boolean);
begin
  CkDh_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TDh.GetG: Integer;
begin
  Result := CkDh_get_G(FHandle);
end;

function TDh.GetP: string;
begin
  Result := CkToStr(CkDh_get_P(FHandle));
end;

function TDh.CreateE(numBits: Integer): string;
begin
  Result := CkToStr(CkDh_CreateE(FHandle, numBits));
end;

function TDh.FindK(const E: string): string;
begin
  Result := CkToStr(CkDh_FindK(FHandle, PAnsiChar(StrToCk(E))));
end;

function TDh.GenPG(numBits: Integer; G: Integer): Boolean;
begin
  Result := Boolean(CkDh_GenPG(FHandle, numBits, G));
end;

function TDh.SetPG(const p: string; g: Integer): Boolean;
begin
  Result := Boolean(CkDh_SetPG(FHandle, PAnsiChar(StrToCk(p)), g));
end;

procedure TDh.UseKnownPrime(index: Integer);
begin
  CkDh_UseKnownPrime(FHandle, index);
end;

initialization
  Chilkat_GetProcedureAddress(CkDh_Create,  'CkDh_Create');
  Chilkat_GetProcedureAddress(CkDh_Dispose, 'CkDh_Dispose');
  Chilkat_GetProcedureAddress(CkDh_get_LastErrorHtml, 'CkDh_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkDh_get_LastErrorText, 'CkDh_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkDh_get_LastErrorXml, 'CkDh_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkDh_get_Version, 'CkDh_get_Version');
  Chilkat_GetProcedureAddress(CkDh_get_DebugLogFilePath, 'CkDh_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkDh_put_DebugLogFilePath, 'CkDh_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkDh_get_VerboseLogging, 'CkDh_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkDh_put_VerboseLogging, 'CkDh_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkDh_get_LastMethodSuccess, 'CkDh_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkDh_put_LastMethodSuccess, 'CkDh_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkDh_get_G, 'CkDh_get_G');
  Chilkat_GetProcedureAddress(CkDh_get_P, 'CkDh_get_P');
  Chilkat_GetProcedureAddress(CkDh_CreateE, 'CkDh_CreateE');
  Chilkat_GetProcedureAddress(CkDh_FindK, 'CkDh_FindK');
  Chilkat_GetProcedureAddress(CkDh_GenPG, 'CkDh_GenPG');
  Chilkat_GetProcedureAddress(CkDh_SetPG, 'CkDh_SetPG');
  Chilkat_GetProcedureAddress(CkDh_UseKnownPrime, 'CkDh_UseKnownPrime');

end.
