{"id":199,"date":"2024-07-23T16:01:37","date_gmt":"2024-07-23T15:01:37","guid":{"rendered":"https:\/\/vgdata.dk\/blog\/?p=199"},"modified":"2024-07-23T16:02:24","modified_gmt":"2024-07-23T15:02:24","slug":"code-templates-for-automatisation","status":"publish","type":"post","link":"http:\/\/vgdata.dk\/blog\/?p=199","title":{"rendered":"code templates for automatisation"},"content":{"rendered":"\n<p>My project is supposed to be used in different countries, so I need to make sure it can be translated.<br>This requires heavy use of resource strings. you can take a look at the documentation:<br><a href=\"https:\/\/wiki.freepascal.org\/Step-by-step_instructions_for_creating_multi-language_applications\">https:\/\/wiki.freepascal.org\/Step-by-step_instructions_for_creating_multi-language_applications<\/a><br>so I declare the string like this: rsTotal = &#8216;Total&#8217;;<br>Then I will add this to a stringlist, where I can use a &#8220;key value pair&#8221;<br>rsStrings.Append(&#8216;rsTotal=&#8217;+rsTotal);<br>This typing is tedious, so I have created a code template:<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/vgdata.dk\/blog\/wp-content\/uploads\/2024\/07\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"494\" src=\"https:\/\/vgdata.dk\/blog\/wp-content\/uploads\/2024\/07\/image-3.png\" alt=\"\" class=\"wp-image-200\" style=\"width:667px;height:auto\" srcset=\"http:\/\/vgdata.dk\/blog\/wp-content\/uploads\/2024\/07\/image-3.png 605w, http:\/\/vgdata.dk\/blog\/wp-content\/uploads\/2024\/07\/image-3-300x245.png 300w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/figure>\n\n\n\n<p>All need now os set the caption on the label to rsTotal, and copy it to the clipboard.<br>Now typing rs^j , will do the typing for me.<\/p>\n\n\n\n<p>Using these procedures in the onCreate event will then translate everything on the form for me:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>procedure TransCaption(MyForm: TForm; rsStrings: TStringList);\nvar\n  i: integer;\nbegin\n  MyForm.Caption:=chgCap(Myform.Caption,rsStrings);\n  for i := 0 to Pred(Myform.ComponentCount) do\n  begin\n    if MyForm.Components&#91;i] is TLabel then\n    (Myform.Components&#91;i] as TLabel).Caption := chgCap((Myform.Components&#91;i] as TLabel).Caption,rsStrings);\n\n    if MyForm.Components&#91;i] is TAction then\n       (Myform.Components&#91;i] as TAction).Caption := chgCap((Myform.Components&#91;i] as TAction).Caption,rsStrings);\n\n    if MyForm.Components&#91;i] is TMenuItem then\n    (Myform.Components&#91;i] as TMenuItem).Caption := chgCap((Myform.Components&#91;i] as TMenuItem).Caption,rsStrings);\n\n    if MyForm.Components&#91;i] is TButton then\n      (Myform.Components&#91;i] as TButton).Caption := chgCap((Myform.Components&#91;i] as TButton).Caption,rsStrings);\n\n\n    if MyForm.Components&#91;i] is TRadioGroup then\n      (Myform.Components&#91;i] as TRadioGroup).Caption := chgCap((Myform.Components&#91;i] as TRadioGroup).Caption,rsStrings);\n\n    if MyForm.Components&#91;i] is TTabsheet then\n      (Myform.Components&#91;i] as TTabsheet).Caption := chgCap((Myform.Components&#91;i] as TTabsheet).Caption,rsStrings);\n\n  end;\nend;\n\nFunction ChgCap(MyCap: TCaption; rsStrings: TStringList):TCaption;\nbegin\n  if Copy(MyCap, 1, 2) = 'rs' then\n    MyCap := rsStrings.values&#91;MyCap];\n  Result := MyCap;\nend;\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My project is supposed to be used in different countries, so I need to make sure it can be translated.This requires heavy use of resource strings. you can take a look at the documentation:https:\/\/wiki.freepascal.org\/Step-by-step_instructions_for_creating_multi-language_applicationsso I declare the string like this: &hellip; <a href=\"http:\/\/vgdata.dk\/blog\/?p=199\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11,10,12],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fpc","tag-lazarus","tag-linux-mint"],"_links":{"self":[{"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/199"}],"collection":[{"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199"}],"version-history":[{"count":3,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":203,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/199\/revisions\/203"}],"wp:attachment":[{"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vgdata.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}