1) I have a Type, which use as a variable.
I want to ahve an array of 64 bytes as:
public void Whatever(TData stuff)
{
sdafsdf = stuff[4]; // TData is byte[64]
Assuming in Delphi you have type definitions along the lines of
type
T64BytesArray = array [0..63] of byte;
Then the answer is no. C# Doesn't allow those kinds of declarations.
You either have to have the method accept a byte array, and perform
bounds checks within that method, or you'll have to define a custom
class or struct which internally defines an array of that size, and
enforces access to it to be within those bounds.
2) Same, but with a record of mixed variables:
public void Whatever(TData stuff)
{
string sdafsdf = stuff[4].name;
int sdafsdf = stuff[4].age;
The same principle applies here. If the type declaration of TData is
something like:
type
TMyStuff = record
name: string;
age: Integer;
end;
TData = array [0..4] of TMyStuff;
then it won't work without you building a custom class or struct.
If you're ok with accepting an array (or list, collection) of arbitrary
length, then both in case 1) and 2), you could just use any array, list
or collection, and do the bounds checks in the method. If you don't wish
to check for them in every method, you'll have to wrap them in a
separate class (and deal with out-of-bounds accesses there).
3) delegates
Something as simple as TNotifyEvent - ?
The basic event system is almost similar to Delphi: You declare a field
(an "event" in C#), which type is of a procedural type (a delegate in
C#). When "something" happens, you check if the field is assigned, and
invoke the assigned method:
{Delphi}
type
TCallback = procedure(sender: TObject; data: TSomeData) of object;
TEventRaiser = class
private
....
FCallback: TCallback;
....
public
SomethingHappened: TCallback read FCallback write FCallback;
end;
....
// somewhere in the class implementation...
if (FCallback <> nil) then FCallback(self, <....>);
{C#}
public delegate void Callback(object sender, EventArgs e);
public class EventRaiser
{
....
public event Callback SomethingHappened;
....
}
// somewhere in the class implementation...
if (SomethingHappened != null)
{
SomethingHappened(this, <....>);
}
This is the basic pattern. You can read up on it here:
http://msdn.microsoft.com/en-us/library/aa645739(VS.71).aspx
4) threading
In Delphi there is "synchronize" - a way to "call" an event elsewhere.
It is done by adding a message to windows - meaning my thread will
continue, and the called procedure will be called when windows passes
the message on.
Can I do the same?
Synchronize in Delphi is mostly (ab)used to update the UI thread from
another thread (as a side note: IIRC "Synchronize" does /not/ just post
a message to the message queue; it posts the message and blocks the
calling thread until the posted message gets handled, making it as evil
as the "Application.ProcessMessages" method).
Pete suggested several possible solutions specifically for exactly that
scenario: BackgroundWorker and/or Control.Invoke. You can learn more
about them here:
http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx