Question
· Oct 14, 2023

Delphi 11 Front end to Cache Database

Hi,

Any examples please of connection a Delphi 11 Front end to a Cache database?

I can get it to connect but then when I try and view data it fails

 

4 fields in front end

SERVER = 127.0.0.1

PORT = 1972

NAMESPACE = DROP DOWN LIST (I SELECT "DEVELOP" FROM THE LIST

EDIT_CLASSNAME = Default value is Test (with maybe 3 fields just of random stuff)

 

 

procedure TFMAIN.BtnConnectClick(Sender: TObject);
 var
 ConnectString: string;
 Success: Boolean;
 Col,Row:Integer;
 FieldName:array[0..10] of string;
begin

    IF NAMESPACE.TEXT<='' THEN
     BEGIN
      SHOWMESSAGE('Please select a Namespace from the drop down list');
      NAMESPACE.SETFOCUS;
      EXIT;
     END;
    //Create instance of the TFactory object
    Factory :=  TFactory.Create(nil);
    //Establish connection with the server if there is no connection
    if not Factory.IsConnected then
     BEGIN
      {
       You can explicitly specify the connection string:
       cn_iptcp - connection protocol
       127.0.0.1 - Ip or sever name(Local Server)
       [1972]      - Port number
       DEVELOP     - Namespace
      }

      //ConnectString := 'cn_iptcp:127.0.0.1[1972]:DEVELOP';
      //ConnectString := 'cn_iptcp:127.0.0.1[1972]:DEVELOP:User:Pass';
      ConnectString := 'cn_iptcp:'+SERVER.TEXT+'['+PORT.TEXT+']:'+NAMESPACE.TEXT;
      Success := Factory.Connect1(ConnectString);
     END;

    if not Success then
     begin
      ShowMessage('Could not connect!');
      //Close the application if the connection fail.
      //Application.Terminate;
      BtnOpenObject.Enabled:=FALSE;
      EXIT;
     end;

    outputMemo.Text := 'Connected to '+ConnectString;
    BtnOpenObject.Enabled:=TRUE;
end;

 

;-------------------------------------------------------------------------------------------------------------

 

procedure TFMAIN.BtnOpenObjectClick(Sender: TObject);
var
 sql:String;
begin
 tmp:=EDIT_CLASSNAME.TEXT;  //Angio.Episode1
 IF tmp<='' THEN
  BEGIN
   SHOWMESSAGE('Enter an Object name');
   EDIT_CLASSNAME.SETFOCUS;
   EXIT;
  END;

 sql:='SELECT * FROM '+tmp;

TRY
 //SQLQuery1.DatabaseName:='CacheDelphi';
 //SQLCONNECTION1.ConnectionName:='CacheDelphi';

 //-------------------------------------------------
 //driver names can be found here
 //C:\Windows\System32\odbcad32.exe
    //InterSystems IRIS ODBC35
    //InterSystems ODBC
    //InterSystems ODBS35
    //MySQL ODBC 8.0 ANSI Driver
    //MySQL ODBC 8.0 Unicode Driver
    //ODBS Driver 17for SQL Server
    //SQL Server
    //SQL Server Native Client 11.0
 //-------------------------------------------------

 SQLCONNECTION1.DriverName:='InterSystems ODBS35';   //DEVELOP

 //SQLConnection1.Params.Values['Database'] := 'CacheDelphi';
 //SQLConnection1.Params.Values['HostName'] := NAMESPACE.TEXT;   //DEVELOP
 SQLConnection1.Params.Values['User_Name'] := '_SYSTEM';
 //SQLConnection1.Params.Values['Password'] := '';

 SQLQuery1.CLOSE;
 SQLQuery1.SQL.CLEAR;
 SQLQuery1.SQL.ADD(sql);
 SQLQuery1.OPEN;
  except
    on E: Exception do
      outputMemo.Text := 'ERROR: ' + E.Message;
  end;
  // Show the results of the query in a TMemo control.
  ShowSelectResults();

end;

 

;-------------------------------------------------------------------------------------------------------------

 

//show results in memo
procedure TFMAIN.ShowSelectResults();
var
  names: TStringList;
  i: Integer;
  currentField: TField;
  currentLine: string;
begin
  if not SQLQuery1.IsEmpty then
  begin
    SQLQuery1.First;
    names := TStringList.Create;
    try
      SQLQuery1.GetFieldNames(names);
      while not SQLQuery1.Eof do
      begin
        currentLine := '';
        for i := 0 to names.Count - 1 do
        begin
          currentField := SQLQuery1.FieldByName(names[i]);
          currentLine := currentLine + ' ' + currentField.AsString;
        end;
        outputMemo.Lines.Add(currentLine);
        SQLQuery1.Next;
      end;
    finally
      names.Free;
    end;
  end;
end;
 

 

 

 

 

 

 

Jason

Discussion (0)1
Log in or sign up to continue