Autor Beitrag
InCoBra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 43



BeitragVerfasst: Do 02.10.08 15:41 
Hey,

ich habe mal wieder ein Problem, unzwar möchte ich gerne folgendes machen (Teils ist das Pseudocode):

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
public void Test(object param_Object)
{
   System.Type type = param_Object.GetType();
   (type) tO = (type)param_Object;

   ...
}



Geht das irgendwie?

Gruß,
InCoBra
InCoBra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 43



BeitragVerfasst: Do 02.10.08 16:54 
So ich habe das jetzt mit Reflection gelöst...

Falls jemand in einem Programm oft Steuerelemente aus anderen Threads setzen muss, dann hier mal meine Funktion:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
        /// <summary>
        /// Delegate für die Invoke-Funktion
        /// </summary>
        /// <param name="param_Object">Das Control bei dem die Eigenschaft gesetzt werden soll.</param>
        /// <param name="param_Property">Die Eigenschaft die gesetzt werden soll.</param>
        /// <param name="param_Value">Der Wert der gesetzt werden soll.</param>
        delegate void Delegate_SetControlSafely(Control param_Control, String param_Property, Object param_Value);

        /// <summary>
        /// Jetzt eine Eigenschaft eines Controls per Invoke.
        /// </summary>
        /// <param name="param_Control">Das Control bei dem die Eigenschaft gesetzt werden soll.</param>
        /// <param name="param_Property">Die Eigenschaft die gesetzt werden soll.</param>
        /// <param name="param_Value">Der Wert der gesetzt werden soll.</param>
        private void SetControlSafely(Control param_Control, String param_Property, Object param_Value)
        {
            if (!CallBack_Deactivate)
            {
                if (param_Control.InvokeRequired)
                {
                    Delegate_SetControlSafely Delegate = new Delegate_SetControlSafely(SetControlSafely);
                    this.Invoke(Delegate, new object[] { param_Control, param_Property, param_Value });
                }
                else
                {
                    try
                    {
                        Type t = param_Control.GetType();
                        t.GetProperty(param_Property).SetValue(param_Control, param_Value, null);
                    }
                    catch
                    {
                        throw new Exception("Du hast versucht, eine nicht existierende Eigenschaft zu setzen.");
                    }
                }
            }
        }
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 02.10.08 17:42 
Mir ist gerade nicht klar, wozu Du das brauchst :gruebel:

Die C#-Syntax für anonyme Methode weiß ich gerade nicht mehr, aber in Oxygene kann man es einfach so machen:

ausblenden Delphi-Prism-Quelltext
1:
2:
3:
self.Invoke(methodbegin
  button1.Text = 'foobar';
end);


Das geht auch in C#.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".