Forum > General

Can Absolute be used on string / packed record

<< < (2/17) > >>

Bart:
Depends on the format of the file.
There are components that read/write CSV files.
Most likely they internally use Copy() and other string manipulating routines.

Bart

MarkMLl:

--- Quote from: Awkward on June 27, 2022, 09:28:56 pm ---You can use 'Absolute' for string (why not?)

--- End quote ---

Because in the general case "a string" might be a shortstring (e.g. string[100] with 100 + 1 elements) or an ansistring etc. where the descriptor (term used loosely) is an opaque data structure referencing the actual text which is stored on the heap.

I'd expect absolute to be applicable to the first case, but not- safely- to the second.

I'd similarly expect the first case to be safe in a (Pascal-style) record which describes a record in a file, but not- safely- the second.

That's why, if you're messing with a low-level API and need the address of the text in a string S, you always use @S[1] rather than @S which might be stored non-contiguously.

MarkMLl

marcov:

--- Quote from: MarkMLl on June 28, 2022, 08:25:34 pm ---Because in the general case "a string" might be a shortstring (e.g. string[100] with 100 + 1 elements) or an ansistring etc. where the descriptor (term used loosely) is an opaque data structure referencing the actual text which is stored on the heap.

--- End quote ---

Declared with [] it will be a shortstring.

MarkMLl:

--- Quote from: marcov on June 28, 2022, 09:45:05 pm ---Declared with [] it will be a shortstring.

--- End quote ---

Yes, I'm attempting to qualify an overbroad assertion (not from OP).

MarkMLl

jamie:
what find interesting is this generating an internal error!


--- 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 TForm1.Button1Click(Sender: TObject);Var  S:string[100];  A:Char absolute S[1];begin  //end;       
S is a short string so it should allow this but I get an internal compiler error.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version