Click here to Skip to main content
15,896,730 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 6:24
mvaMarc Clifton10-Feb-04 6:24 
GeneralRe: Cannot abort thread Pin
David Stone10-Feb-04 9:06
sitebuilderDavid Stone10-Feb-04 9:06 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 9:38
mvaMarc Clifton10-Feb-04 9:38 
GeneralRe: Cannot abort thread Pin
David Stone10-Feb-04 10:36
sitebuilderDavid Stone10-Feb-04 10:36 
GeneralRe: Cannot abort thread Pin
Marc Clifton10-Feb-04 13:40
mvaMarc Clifton10-Feb-04 13:40 
Questionhow to draw a X coordinate with a series of datetime data? Pin
Member 185560810-Feb-04 3:22
Member 185560810-Feb-04 3:22 
AnswerRe: how to draw a X coordinate with a series of datetime data? Pin
Alex Korchemniy10-Feb-04 7:20
Alex Korchemniy10-Feb-04 7:20 
Generalinteract 2 way Pin
Blue_Aqua10-Feb-04 3:14
Blue_Aqua10-Feb-04 3:14 
GeneralRe: interact 2 way Pin
Heath Stewart10-Feb-04 11:10
protectorHeath Stewart10-Feb-04 11:10 
GeneralRe: interact 2 way Pin
Blue_Aqua10-Feb-04 18:23
Blue_Aqua10-Feb-04 18:23 
GeneralMultyThreading in C#: Communication between threads Pin
Jasper4C#10-Feb-04 2:46
Jasper4C#10-Feb-04 2:46 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Marc Clifton10-Feb-04 4:17
mvaMarc Clifton10-Feb-04 4:17 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Jasper4C#10-Feb-04 12:08
Jasper4C#10-Feb-04 12:08 
GeneralRe: MultyThreading in C#: Communication between threads Pin
Marc Clifton10-Feb-04 13:38
mvaMarc Clifton10-Feb-04 13:38 
GeneralBackground compile in C# Pin
mufoxe10-Feb-04 2:24
mufoxe10-Feb-04 2:24 
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 

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.