Forum > General
Getting info that is very volatile.
alpine:
Although the dseligo program is working perfectly, I would like to propose another version for Convert procedure using a slightly different approach (with TStringHelper). That way It is a bit clearer and shorter, I believe.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Convert;var I, J, N: Integer; A, B: TStringArray; S, ST: AnsiString; First: Boolean; // Assign array[1..3] of String from TStringArray // Would be no need for it if Gods, Taverns, Trade were declared as TStringArray procedure AssignTgtt(var Dest: Tgtt; const Src: TStringArray); var I: Integer; begin for I := 1 to Math.Min(Length(Dest), Length(Src)) do Dest[I] := Src[Pred(I)]; end; begin for I := 1 to Recds do begin A := Fileline[I].Split(['.']); First := True; for S in A do begin ST := Trim(S); if First then // Handle the first sentence begin B := ST.Split([' - Pop ', ' (', ' fams)']); Villages[I].Name := B[0]; Villages[I].Population := StrToInt(B[1]); Villages[I].Families := StrToInt(B[2]); First := False; end else if ST.StartsWith('Gov:') then // Handle Gov: ... . Villages[I].Government := ST.Substring(5) else if ST.StartsWith('Shrine') then // Handle Shrine(s) to ..., ... and ... . AssignTgtt(Villages[I].Gods, Trim(ST.Substring(10)).Split([', ', ' and '])) else if ST.StartsWith('Inn:') then // Handle Inn: ... . Villages[I].Inn := ST.Substring(5) else if ST.StartsWith('Taverns:') then // Handle Taverns: ..., ... . AssignTgtt(Villages[I].Taverns, ST.Substring(9).Split([', '])) else if ST.StartsWith('Trade:') then // Handle Trade: ..., ... . AssignTgtt(Villages[I].Trade, ST.Substring(7).Split([', '])) else if ST.Length > 0 then // Handle number of different villagers begin B := ST.Split([', ', ' ']); for J := 0 to High(B) do if Odd(J) then // Kind is at odd positions: 1, 3, ... case B[J].Substring(0, 5) of 'farme': Villages[I].Farmers := N; 'artis': Villages[I].Artisans := N; 'labor': Villages[I].Laborers := N; 'paupe': Villages[I].Paupers := N; end else N := StrToInt(Trim(B[J])); // number is at even: 0, 2, ... end; end; end;end;
Thaddy:
If you want to use the type helpers, why do not do it consistently?
There is a whole lot of rewrites to be done in that case, like for in do and obviously not this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- N := StrToInt(Trim(B[J])); // number is at even: 0, 2, ...But This:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- N := B[J].trim.ToInteger; // number is at even: 0, 2, ...Also you declare the array as one based and "real programmers count from zero", so the test should be the other way around.
Try to be consistent in the way you use features.
alpine:
--- Quote from: Thaddy on January 30, 2023, 01:37:00 pm ---Also you declare the array as one based and "real programmers count from zero", so the test should be the other way around.
--- End quote ---
I would recommend reading the posts more carefully before commenting.
Thaddy:
I did. I would recommend to learn to count.
alpine:
--- Quote from: Thaddy on January 30, 2023, 06:42:29 pm ---I did. I would recommend to learn to count.
--- End quote ---
Could you please be more specific, on which source line the counting is wrong?
Navigation
[0] Message Index
[#] Next page
[*] Previous page