有没有办法将此delphi代码转换为c ++ builder [英] Is there a way to convert this delphi code to c++builder

查看:37
本文介绍了有没有办法将此delphi代码转换为c ++ builder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数情况下,我能够将Delphi转换为C ++,但这使我有些头疼.也许有些人可以帮忙.

In most cases I am able to convert Delphi to C++, but this one gives me some headache. Maybe some of you could help.

在此链接中此处,其中引用了一些在Embarcadero(FMX)的TListView上添加了新功能.由于我对C ++的了解比对Delphi的了解要多得多,因此我使用C ++ Builder.在大多数情况下,翻译和理解并找到解决方法是完全可以的.但是在这里我被困住了:

As seen in this link here, which references some new functions on TListView in Embarcadero (FMX). As I am much more comfortable with C++ than Delphi I use C++Builder. In most cases this is quite Ok to translate and understand, and find workarounds. But here I am stuck:

procedure TForm1.FormCreate(Sender: TObject);
I: Integer;
begin
// ListView1 uses a classic Appearance
for I in [0..63] do
with ListView1.Items.Add do
begin
  Text := Format('%d pages', [1000 + Random(1234567)]);
  Detail := Format('%d kg of paper', [1000 + Random(1234)]);
  ImageIndex := Random(ImageList1.Count);
end;

// ListView4 uses a dynamic appearance with items named
// Text1, Detail1, Portrait
for I in [0..63] do
with ListView4.Items.Add do
begin
  Data['Text1'] := Format('%d pages', [1000 + Random(1234567)]);
  Data['Detail1'] := Format('%d kg of paper', [1000 + Random(1234)]);
  Data['Portrait'] := Random(ImageList1.Count);
end;
end;

end. 

我正在苦苦挣扎的部分是

The section I am struggling with is

with ListView4.Items.Add do
begin
  Data['Text1'] := Format('%d pages', [1000 + Random(1234567)]);
  Data['Detail1'] := Format('%d kg of paper', [1000 + Random(1234)]);
  Data['Portrait'] := Random(ImageList1.Count);
end;

这是怎么翻译的,或者此功能在c ++中根本不存在?

How is this translated, or is this functionality which simply doesn't exists in c++ ?

推荐答案

要将项目添加到ListView时,首先需要使用Add()函数创建项目对象(TListViewItem *),该对象是TListView的Items的子级财产.然后,item的Data属性需要TValue,因此您需要从字符串或要放入该项目的其他内容中获取TValue.请记住在片段之前使用BeginUpdate(),在片段添加元素后将其添加到ListView和EndUpdate(),以提高此操作的性能.

When you want to add an item to a ListView you need to first create an item object (TListViewItem*) using Add() function that is child of TListView's Items property. Then, the Data property of item is expecting TValue, so you need to get TValue from a string or something else you want to put in the item. Remember to use BeginUpdate() before fragment where you are adding items to ListView and EndUpdate() after to improve the performance of this operation.

ListView4->BeginUpdate();

TListViewItem* item = ListView4->Items->Add();
UnicodeString string1 = "content of the String";

item->Data["Text1"] =  TValue::From<UnicodeString>(string1);
item->Data["Detail1"] = TValue::From<UnicodeString>(string1); 
item->Data["visitTime"] =TValue::From<int>(Random(ImageList1->Count)) 

ListView4->EndUpdate();

这篇关于有没有办法将此delphi代码转换为c ++ builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆