delphi 6 - how to use the function "copy" to assign a UTF-8 value to a variable -
i use following code assign text sql parameter:
quinsert.parameters.parambyname('veh_type').value := copy(s,11,1);
sometimes text in .txt
file reading in utf-8, has characters using 2 bytes. how can change following code accept utf-8 data?
procedure tprepareform.button1click(sender: tobject); var f : textfile; s : string; : integer; isansistring : boolean; begin quinsert begin close; sql.clear; sql.add('insert v_info_2018'); sql.add('(record_type, plate_group, plate_no, v_type, v_type_cn,'); sql.add('v_type_pt, v_type_pt, v_brand, engine_no, ct_tax_amount'); sql.add('inspect_date, record_date'); sql.add('values (:record_type, :plate_group, :plate_no, :v_type, :v_type_cn, :v_type_pt, :v_type_pt,'); sql.add(':v_brand, :engine_no, :ct_tax_amount,'); sql.add(':inspect_date, :record_date'); end; := 0; assignfile(f,edmastername.text); reset(f); while not eof(f) begin readln(f,s); inc(i); end; prinsert.max := i; := 0; reset(f); vrs_main.statusbar1.panels[5].text:='0'; while not eof(f) begin inc(i); prinsert.stepit; readln(f,s); quinsert.parameters.parambyname('record_type').value := copy(s,1,1); quinsert.parameters.parambyname('plate_group').value := copy(s,2,1); quinsert.parameters.parambyname('plate_no').value := copy(s,3,8); quinsert.parameters.parambyname('v_type').value := copy(s,11,1); quinsert.parameters.parambyname('v_type_cn').value := utf8decode(copy(s,12,50)); quinsert.parameters.parambyname('v_type_pt').value := copy(s,62,50); quinsert.parameters.parambyname('v_brand').value := copy(s,112,30); quinsert.parameters.parambyname('engine_no').value := copy(s,142,50); quinsert.parameters.parambyname('ct_tax_amount').value := copy(s,192,9); quinsert.parameters.parambyname('inspect_date').value := copy(s,201,50); quinsert.parameters.parambyname('record_date').value := copy(s,251,8); quinsert.execsql; vrs_main.statusbar1.panels[5].text:=inttostr(strtoint(vrs_main.statusbar1.panels[5].text)+1); end; end;
store utf-8 data in utf8string
instead of standard string
, , call either utf8decode()
or utf8toansi()
, store result in database.
wiki
Comments
Post a Comment