Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Rewrite a Delphi program to C#

Posted on 2009-07-10
5
656 Views
Last Modified: 2013-12-17
Hi,

I am trying to rewrite a program sample thats written in Delphi to C#.

The connector is working, what I need help with is how to write the code currently in Delphi to work for C#.
It uses the GroupwareTypeLibrary class in C#.

Before you dig in to the Delphi code below, I would like to point out that I am a novice at C#, examples in code are great =)
Below is the Delphi code).

What I really just need is account date of appointment, timestart of appt, timeend of appt, dateend of appt.
The Cellthing in there is not needed, I just want the date & time of the appointments :-)
*}
 
 
unit search;
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, COMOBJ, OleCtrls, GWNCCLib_TLB, Grids, GWABLib_TLB ;
 
type
  TForm1 = class(TForm)
    StringGrid: TStringGrid;
    bSearch: TButton;
    bClear: TButton;
    bClose: TButton;
    Label1: TLabel;
    lCurrentDate: TLabel;
    Label3: TLabel;
    GWName: TGWncc;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure bSearchClick(Sender: TObject);
    procedure bCloseClick(Sender: TObject);
    procedure bClearClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    vBusySearchResult:variant;
    vAccount:variant;
    vMessages:variant;
    vDraft:variant;
    vRecipients:variant;
    vRecipient:variant;
    oneHour:double;
    twoHours:double;
    threeHours:double;
    fourHours:double;
    fiveHours:double;
    sixHours:double;
    sevenHours:double;
    eightHours:double;
    nineHours:double;
    tenHours:double;
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
uses
splash;
 
procedure TForm1.FormCreate(Sender: TObject);
var
   GroupWise:variant;
   vMailBoxFolder:variant;
 
begin
     GroupWise:=CreateOleObject('NovellGroupWareSession');
     vAccount:=GroupWise.Login;
 
     vMailBoxFolder:=vAccount.MailBox;
     vMessages:=vMailBoxFolder.Messages;
     vDraft:=vMessages.Add('GW.MESSAGE.APPOINTMENT');
 
     StringGrid.RowCount:=2;
     StringGrid.ColWidths[0]:=StringGrid.DefaultColWidth +30;
 
     StringGrid.Cells[0,0]:= '    TIME:';
     StringGrid.Cells[1,0]:=inttostr(7);
     StringGrid.Cells[2,0]:=inttostr(8);
     StringGrid.Cells[3,0]:=inttostr(9);
     StringGrid.Cells[4,0]:=inttostr(10);
     StringGrid.Cells[5,0]:=inttostr(11);
     StringGrid.Cells[6,0]:=inttostr(12);
     StringGrid.Cells[7,0]:=inttostr(1);
     StringGrid.Cells[8,0]:=inttostr(2);
     StringGrid.Cells[9,0]:=inttostr(3);
     StringGrid.Cells[10,0]:=inttostr(4);
     StringGrid.Cells[11,0]:=inttostr(5);
     StringGrid.Cells[12,0]:=inttostr(6);
 
     oneHour:= 1/24;
     twoHours:= 2/24;
     threeHours:= 3/24;
     fourHours:= 4/24;
     fiveHours:= 5/24;
     sixHours:= 6/24;
     sevenHours:= 7/24;
     eightHours:= 8/24;
     nineHours:= 9/24;
     tenHours:= 10/24;
end;
 
procedure TForm1.bSearchClick(Sender: TObject);
var
   vBusySearchElements:variant;
   vBusySearchElement:variant;
   vTimeBlocks:variant;
   vTimeBlock:variant;
   i:integer;
   j:integer;
   k:integer;
   TimeString:string;
   StartDate:string;
   HourString:string;
label
   Done;
begin
     bSearch.Enabled:= not bSearch.Enabled;
 
     if GWName.Count=0 then begin
        ShowMessage('Please type in a person');
        GWName.SetFocus;
     end;
 
     vRecipients:=vDraft.Recipients;
     StringGrid.RowCount:=GWName.Count+1;
     for i:=0 to GWName.Count-1 do begin
         vRecipient:=vRecipients.AddByDisplayName(GWName.DisplayName(i));
         StringGrid.Cells[0,i+1]:=GWName.DisplayName(i);
     end;
     GWName.Clear;
 
 
   //Starting busy search
   vBusySearchResult:=vDraft.StartBusySearch;
   lCurrentDate.Caption:=vBusySearchResult.StartDate;
 
   vBusySearchElements:=vBusySearchResult.BusySearchElements;
   //Busy Search Loop
   while (vBusySearchResult.Completed = FALSE) do begin
         splash.Wait.ShowModal;
         Application.ProcessMessages;
   end;
 
   //Double loop (get to BusySearchElement collection then TimeBlock collection)
   for i:=1 to vBusySearchElements.Count do begin
       vBusySearchElement:=vBusySearchElements.Item(i);
       vTimeBlocks:=vBusySearchElement.TimeBlocks;
       for j:=1 to vTimeBlocks.Count do begin
           vTimeBlock:=vTimeBlocks.Item(j);
           if vTimeBlock.ObjType = 1 then begin
              StartDate:=DateToStr(vTimeBlock.StartDate);
              TimeString:=TimeToStr(vTimeBlock.StartDate);
              HourString:=Copy(TimeString,1, pos(':',TimeString)-1);
              if StartDate <> lCurrentDate.Caption then
                 goto Done;
              for k:=1 to 12 do begin
                  if StringGrid.Cells[k,0] = HourString then begin
                     StringGrid.Cells[k,i]:= 'XXX';
                     if vTimeBlock.duration > twoHours then begin
                        StringGrid.Cells[k+1,i]:= 'XXX';
                        if vTimeBlock.duration > threeHours then begin
                           StringGrid.Cells[k+2,i]:= 'XXX';
                           if vTimeBlock.duration > fourHours then begin
                              StringGrid.Cells[k+3,i]:='XXX';
                              if vTimeBlock.duration > fiveHours then begin
                                 StringGrid.Cells[k+4,i]:='XXX';
                                 if vTimeBlock.duration > sixHours then begin
                                    StringGrid.Cells[k+5,i]:='XXX';
                                    if vTimeBlock.duration > sevenHours then begin
                                       StringGrid.Cells[k+6,i]:='XXX';
                                       if vTimeBlock.Duration > eightHours then begin
                                          StringGrid.Cells[k+7,i]:='XXX';
                                          if vTimeBlock.Duration > nineHours then begin
                                             StringGrid.Cells[k+8,i]:='XXX';
                                             if vTimeBlock.Duratoin > tenHours then begin
                                                StringGrid.Cells[k+9,i]:='XXX';
                                             end;
                                          end;
                                       end;
                                    end;
                                 end;
                              end;
                           end;
                        end;
                     end;
                  end;
              end;
           end;
       end;
       vBusySearchResult.Refresh;
Done:
end;
    ShowMessage('Done.');
end;
 
procedure TForm1.bCloseClick(Sender: TObject);
begin
   close;
end;
 
procedure TForm1.bClearClick(Sender: TObject);
var
   i:integer;
   j:integer;
begin
     bSearch.Enabled:= not bSearch.Enabled;
     bClear.Enabled:= not bClear.Enabled;
     i:=vRecipients.Count;
     While (vRecipients.Count >0) do begin
         StringGrid.Cells[0,i]:='';
         vRecipient:=vRecipients.Item(i);
         vRecipient.Delete;
         i:=i-1;
     end;
     for i:= 1 to StringGrid.RowCount do begin
         for j:= 1 to 12 do begin
             StringGrid.Cells[j,i]:='';
         end;
     end;
end;
 
end.

Open in new window

0
Comment
Question by:TheFlyingCorpse
  • 3
  • 2
5 Comments
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24828953
Below is my code to connect to the GroupWise server that I've written in C#.

I can supply the COM dll file thats used if you havent already got it =)
        private void btnAppointments_Click(object sender, EventArgs e)
        {
            GroupwareTypeLibrary.Application5 objGWSession = new GroupwareTypeLibrary.Application5();
            GroupwareTypeLibrary.Account objAccount = default(GroupwareTypeLibrary.Account);
            GroupwareTypeLibrary.Appointment objAppointment = default(GroupwareTypeLibrary.Appointment);
 
            string sUserName = textBox3.Text;
            string sTrustedAppKey = textBox2.Text;
            string sTrustedAppName = textBox1.Text;
            string sCmdLine = "/*ipa*-127.0.0.1 /ipp-1677";
            string sWhenToPromp = "egwPromptNever";
            string sPassword = null; // Not neccesary when using a Trusted Application
            string sReserved = null;
            string sApptType = "GW.MESSAGE.APPOINTMENT";
            string sApptClass = null;
            string sApptVersion = null;
            object objRootFolder, objMessages, objDrafts, objBusyUsers;
            
            //Using Trusted Application
            objGWSession.SetTrustedApplicationCredentials(sTrustedAppName, sTrustedAppKey);
            //Using Multilogin
            objAccount = objGWSession.MultiLogin(sUserName, sCmdLine, sPassword, sWhenToPromp, sReserved);
            MessageBox.Show(objAccount.Owner.DisplayName);
    }

Open in new window

0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 24832865
Hi mate!

I used Delphi a long time ago, I wont give it a try converting it but I'll point you to a tool that will do the job for you.

Have a look here: http://www.netcoole.com/delphi2cs.htm

Cheers!
Alex
0
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24832985
I used that and got a rather good result, it shows how one could construct it in C#. It scored 95% converted on the application, it got all except for the cells ;)


I'll investigate it a bit more and get back to you =)
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 24833864
Nice!
It's way better than have to convert it 100% :)

Now, if you have a problem converting a particular piece of code I think you should isolate it.
Create a new Delphi application and add just enough code to test and convert what you need.

Although the result may not be 100% what you need on the real application it will certainly show you how to do it.

Like I said mate, I don't touch Delphi in a while... I think more than a while... say... since around 1996/97 perhaps! But feel free to post any further questions, I'll be happy to help you.

Cheers mate,
Alex
0
 
LVL 2

Author Comment

by:TheFlyingCorpse
ID: 24907071
I found a better solution then rewriting the program, I choose you PERL and the SOAP service thats enabled in our GroupWise POA's ;)
Thanks for the application, it will come very handy as our internal development team is transisting from Delphi to C# ;-)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sent email using Shared Mailbox from outlook in C# 5 47
Help with adding DLL file in Windows project 20 40
tableview is not updating 1 20
Why use this lambda? 12 26
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question