[fpc-pascal] EnumToString

Thomas Young tygraphics at me.com
Tue Nov 1 09:30:30 CET 2011


Hi,

This is code I wrote for converting 1, 2 or 3 digit numbers to string.

	function NumtoString(N:integer):string;
	var
		c1, c2, c3: char;
	begin
		if (N<10) then
			NumtoString := chr(N+48)
		else if (N > 9) and (N < 100) then
			begin
				c1 := chr((N div 10) + 48);
				c2 := chr((N mod 10) + 48);
				NumtoString := concat(c1, c2);
			end
		else if (N > 99) and (N < 1000) then
			begin
				c1 := chr((N div 100) + 48);
				c2 := chr((N mod 100) div 10 + 48);
				c3 := chr((N mod 10) + 48);
				NumtoString := concat(c1, c2, c3);
			end;
	end;

Thomas Young
cell: 330-256-7064
mobile email: tygraphics at me.com



On Nov 1, 2011, at 3:41 AM, Juha Manninen wrote:

> Hi
> 
> I remember there is a way to get a string representation of an enumerated type directly without using a lookup string array, but I forgot the syntax.
> Lazarus uses only lookup arrays, maybe because the other syntax is new.
> 
> How is the syntax?
> 
> Juha
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list