Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi args: array of const ? (https://www.delphipraxis.net/35931-args-array-const.html)

stoxx 13. Dez 2004 22:19


args: array of const ?
 
Hallo !

ich analysiere gerade einen fremden Quelltext.

Da kommt sowas vor:

Code:
procedure tuwas(Value : Integer; args: array of const);
das array of const hab ich noch nie gesehen und kann mir im Moment absolut nicht vorstellen, was und wozu das dienen soll ?
DAnke schonmal !

sniper_w 13. Dez 2004 22:31

Re: args: array of const ?
 
so...
---------------------------------
The array of const construction is equivalent to array of TVarRec. TVarRec, declared in the System unit, represents a record with a variant part that can hold values of integer, Boolean, character, real, string, pointer, class, class reference, interface, and variant types. TVarRec’s VType field indicates the type of each element in the array. Some types are passed as pointers rather than values; in particular, long strings are passed as Pointer and must be typecast to string.
---------------------------------
aus Delphi Hilfe....ganz einfach :stupid: :nerd:

Luckie 13. Dez 2004 22:32

Re: args: array of const ?
 
Guck doch einfach mal in der Hilfe unter: Delphi-Referenz durchsuchenVariant open array parameters.

stoxx 13. Dez 2004 22:42

Re: args: array of const ?
 
Ihr müsst ne andere Hilf als ich haben ! :-(
find ich nicht, egal ..

lese aber gerade im Netz. Mal aber noch eine andere Frage dazu ..

Hier http://www.marcocantu.com/epascal/German/ch06procde.htm
lese ich den Satz:

"Gegenüber C besitzten Pascal-Funktionen und -Prozeduren immer eine feste Anzahl von Parametern. Es gibt jedoch einen Weg, um eine variable Anzahl von Parametern an eine Routine zu übergeben, die Verwendung einen offenen Arrays."

Besteht da ein Unterschied zwischen C# und C ?Also wie sieht das in C# aus ?

Robert_G 13. Dez 2004 23:03

Re: args: array of const ?
 
Zitat:

Zitat von stoxx
Besteht da ein Unterschied zwischen C# und C ?Also wie sieht das in C# aus ?

Code:
using System;

internal class Program
{
   static void PrintSomeWords(params string[] someWords)
   {
      foreach (string word in someWords)
         Console.WriteLine(word);
   }

   public static void Main(string[] args)
   {
      PrintSomeWords("eins", "zwei", "drei");
   }
}
params darf nur für den letzten Parameter benutzt werden. Du kannst damit soviele Parameter übergeben wie du lustig bist. In der Methode landet es als Array.
Ein gutes Beispiel ist:
Code:
   string.Format("{0}, {1}, {2}",
                 "eins",
                 "zwei",
                 "drei");


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:31 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz