Solved

Rewrite a Delphi program to C#

Posted on 2009-07-10
5
645 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now