Re: open save dialog with api
Posted by webmaster Guido on February 17, 2001: In Reply to: pchar & string posted by idname on February 16, 2001:
: How can I convert a var of type PChar to String?? In the following notes, by "string" we mean "long string". In 32 bit Delphi, "string" in fact is a "long string" ("AnsiString"). The old "Delphi 1 string" only exists for backward compatibility and is now called "short string". var S, S1, S2: string; To convert a variable of the type PChar to a string, there are several possibilities: 1. Simply assign the value of a PChar variable to a string variable. The following example copies a null-terminated string into the string variable S: GetWindowsDirectory(P, 256); // a WinAPI function 2. You can mix string values and PChar values in expressions and assignments. For example: S := 'The Windows directory is ' + P; 3. You can pass PChar values as parameters whe re strings are accepted. Example: S := LowerCase(P); 4. You can cast a PChar value as a long string. Example: You can also do the reverse, cast a string as a null-terminated string, such as: // MessageBox is declared in the Windows interface unit In general, you can do this: But be careful: when you cast a long-string expression to a pointer, the pointer should usually be considered READ-ONLY. Using the pointer to modify the long string gives only correct results under very strict conditions, which would lead us to far to explain them here. In general, DO NOT try something like: P := PChar(S); ----------------- P := 'DelphiLand'; Now, P points to an area of memory that contains a null-t
erminated copy of 'DelphiLand'. const arrDelphiLa: array[0..10] of Char = 'DelphiLand'#0; 2. Pass string constants to functions that take PChar parameters, for example: P := StrUpper('DelphiLand'); 3. Initialize PChar constants with string literals, for example: const Welcome: PChar = 'Welcome to DelphiLand!';
|
|