Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRemoting, Events, Interfaces and Assemblies Pin
CyberHawke10-Feb-04 1:35
CyberHawke10-Feb-04 1:35 
GeneralRe: Remoting, Events, Interfaces and Assemblies Pin
Marc Clifton10-Feb-04 1:45
mvaMarc Clifton10-Feb-04 1:45 
GeneralReport Designer Pin
Itanium9-Feb-04 19:56
Itanium9-Feb-04 19:56 
GeneralRe: Report Designer Pin
Marc Clifton10-Feb-04 1:47
mvaMarc Clifton10-Feb-04 1:47 
GeneralRe: Report Designer Pin
Roger Alsing10-Feb-04 2:44
Roger Alsing10-Feb-04 2:44 
GeneralRe: Report Designer Pin
Marc Clifton10-Feb-04 3:50
mvaMarc Clifton10-Feb-04 3:50 
GeneralRe: Report Designer Pin
Itanium10-Feb-04 20:22
Itanium10-Feb-04 20:22 
GeneralTranslating from Delphi to C# - problem with objects. Pin
Andres Coder9-Feb-04 17:48
Andres Coder9-Feb-04 17:48 
Is there any prior Delphi developers here ? I'm trying to translate an program from Delphi to C#. Most of the program is translater now, only the worst part is shown here. P.S. Even if youre not familiar with Delphi, please take a look anyway ...

The problematic part in the code below is mostly the part GetBook procedure. It takes a record TBookInfo (struct in C#) from an array (ArrayList would have a best use in here) and creates and instance of TMyBook type and assignes it to a varable in the record. The tricky part here is that the instance is created the same type as another variable is - TMyBookClass (witch is class of TMyBook). I have no ideas how to do that in C#. Any ideas (some code would be very nice) ?

Can anyone help me with this ?

<br />
program Project;<br />
<br />
{$APPTYPE CONSOLE}<br />
<br />
uses<br />
  SysUtils, Classes;<br />
  <br />
type<br />
  // TMyBook is like an basic adapter. It's decendants provide the application<br />
  // with various functions and variables.<br />
  TMyBook = class<br />
  private<br />
    FName: string;<br />
  public<br />
    constructor Create(const AName: string); virtual;<br />
    property Name: string read FName;<br />
  end;<br />
<br />
  // TMyBookClass - a metaclass of TMyBook type ??? <br />
  TMyBookClass = class of TMyBook;<br />
  // A decendant of TMyBook, will override functions from TMyBook.<br />
  TMyNewBook = class(TMyBook);<br />
<br />
  // Basicly contains information to create, access and<br />
  // manage the TMyBook instance.<br />
  TBookInfo = record<br />
    Name: String;<br />
    BookInstance: TMyBook;<br />
    BookClass: TMyBookClass;<br />
  end;<br />
<br />
var<br />
 // The currently active TMyBook is accessed throught this.<br />
 ActiveBook: TMyBook;<br />
 // An array where all the TBookInfos are stored. <br />
 Books: array of TBookInfo;<br />
<br />
constructor TMyBook.Create(const AName: string);<br />
begin<br />
  FName := AName;<br />
end;<br />
<br />
// Finds a TMyBook by name if there is one present.<br />
function FindBook(const AName: string): Integer;<br />
begin<br />
  for Result := 0 to Length(Books) - 1 do<br />
    if CompareText(Books[Result].Name, AName) = 0 then Exit;<br />
  Result := -1;<br />
end;<br />
<br />
// Fills the TBookInfo with information about the TMyBook.<br />
// It also determines the class type witch is going to be used.<br />
procedure RegisterBookInfo(const AName: string; ABookClass: TMyBookClass);<br />
var<br />
  Index: Integer;<br />
begin<br />
  Index := Length(Books);<br />
  SetLength(Books, Index + 1);<br />
  with Books[Index] do<br />
  begin<br />
    Name := AName;<br />
    BookClass := ABookClass;<br />
    BookInstance := nil;<br />
  end;<br />
end;<br />
<br />
// Returns the instance of a book by name. The hard part here<br />
// is that the instance is created of BookClass type.<br />
function GetBook(const AName: string): TMyBook;<br />
var<br />
  Index: Integer;<br />
begin<br />
  Index := FindBook(AName);<br />
  with Books[Index] do<br />
  begin<br />
    Assert(BookInstance = nil);<br />
    BookInstance := BookClass.Create(Name);<br />
    Result := BookInstance;<br />
  end;<br />
end;<br />
<br />
// Sets up a book instance and assigns it to ActiveBook.<br />
procedure SetActiveBook(const ABookName: string);<br />
begin<br />
  // ReleaseActiveBook;<br />
  ActiveBook := GetBook(ABookName);<br />
end;<br />
<br />
begin<br />
  // First I register the info about the book, usually at program start.<br />
  RegisterBookInfo('New Book', TMyNewBook);              <br />
  // And if I have a need, I activate it. I might as well use any other book<br />
  // and switch between them at runtime with this clause.<br />
  SetActiveBook('New Book');<br />
end.<br />


Regards, Desmond
GeneralRe: Translating from Delphi to C# - problem with objects. Pin
John Kuhn9-Feb-04 19:16
John Kuhn9-Feb-04 19:16 
GeneralRe: Translating from Delphi to C# - problem with objects. Pin
Andres Coder10-Feb-04 2:45
Andres Coder10-Feb-04 2:45 
GeneralRe: Translating from Delphi to C# - problem with objects. Pin
John Kuhn10-Feb-04 10:45
John Kuhn10-Feb-04 10:45 
GeneralCharacter array Pin
GetOn&GetGoing9-Feb-04 17:44
GetOn&GetGoing9-Feb-04 17:44 
GeneralRe: Character array Pin
Nick Parker9-Feb-04 18:28
protectorNick Parker9-Feb-04 18:28 
GeneralRe: Character array Pin
Marc Clifton10-Feb-04 1:49
mvaMarc Clifton10-Feb-04 1:49 
GeneralConversion from string to integer Pin
GetOn&GetGoing9-Feb-04 17:00
GetOn&GetGoing9-Feb-04 17:00 
GeneralRe: Conversion from string to integer Pin
John Kuhn9-Feb-04 17:06
John Kuhn9-Feb-04 17:06 
GeneralRe: Conversion from string to integer Pin
HAHAHA_NEXT10-Feb-04 4:09
HAHAHA_NEXT10-Feb-04 4:09 
GeneralConvert int to byte[4] Pin
Anonymous9-Feb-04 14:04
Anonymous9-Feb-04 14:04 
GeneralRe: Convert int to byte[4] Pin
John Kuhn9-Feb-04 16:11
John Kuhn9-Feb-04 16:11 
GeneralRe: Convert int to byte[4] Pin
HAHAHA_NEXT10-Feb-04 4:01
HAHAHA_NEXT10-Feb-04 4:01 
QuestionWhat hook? Pin
Anonymous9-Feb-04 13:51
Anonymous9-Feb-04 13:51 
AnswerRe: What hook? Pin
Mazdak9-Feb-04 19:42
Mazdak9-Feb-04 19:42 
GeneralRelative file paths Pin
dratti9-Feb-04 13:02
dratti9-Feb-04 13:02 
GeneralFunctions and pointers Pin
Kryal9-Feb-04 11:54
Kryal9-Feb-04 11:54 
GeneralRe: Functions and pointers Pin
Marc Clifton9-Feb-04 13:47
mvaMarc Clifton9-Feb-04 13:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.