Rewrite a Delphi program to C#

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

LVL 2
TheFlyingCorpseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheFlyingCorpseAuthor Commented:
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
Alexandre SimõesManager / Technology SpecialistCommented:
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
TheFlyingCorpseAuthor Commented:
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
Alexandre SimõesManager / Technology SpecialistCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheFlyingCorpseAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.