String TPropertyHandler::GetClassNamesValues(TComponent* comp, String prName) { TObject *subObj = (TObject *)GetOrdProp(comp, prName); if (subObj == NULL) return ""; // In case the prop-value is empty (like Action). /* TObject* subObj is needed to find out if the subprop points to another Component (like ActiveControl). If it is only the value of that property is returned (ie.: "CheckBox1"). If it is a class like Font all of the props+values of comp->Font are returned. */ if (dynamic_cast<TComponent*>(subObj)) { // Find out if subObj points to another Component by casting. return prName + "=" + GetValue((TComponent*)subObj,"Name"); } /* subObj does not point to another Component, but we can convert it to a TComponent* subComp so it can be used te get the subProps+values. This sounds weird but don't forget that a TFont encapsulated in a TForm becomes a descendant of TForm, which is a descendant of TComponent!! */ TComponent* subComp = (TComponent*)subObj; TStringList *tempList = new TStringList; String temp; try { PTypeInfo TypeInfo = (PTypeInfo)subComp->ClassInfo(); PPropInfo* PropList = new TPropList; GetPropInfos(TypeInfo, (PPropList)PropList); tempList->Sorted = true; for (int i=0; i < PropertyCount(subComp); i++) { String subProp = String(PropList[i]->Name); tempList->Add( prName + "." + subProp + "=" + GetPropValue(subComp, subProp, true) ); } delete[] PropList; temp = tempList->Text; // Remove trailing carriage-returns: int cr = temp.LastDelimiter("\r"); if (cr) temp.Delete(cr, 2); } __finally { delete tempList; } return temp; }
void __fastcall TCacheDemoForm::ToggleUpdateMode(System::TObject* Sender) { bool NewState; // Toggle the state of the CachedUpdates property if (IsPublishedProp(FDataSet, "CachedUpdates")) { FDataSet->Close(); NewState = !GetOrdProp(FDataSet, "CachedUpdates"); SetOrdProp(FDataSet, "CachedUpdates", NewState); // Enable/Disable Controls SetControlStates(NewState); FDataSet->Open(); } }
void TPropertyHandler::SetNameValue(TComponent* comp, String prName_Value) { if (prName_Value.LastDelimiter("\r\n")) { // Multi-line string, so call SetNamesValues(): SetNamesValues(comp, prName_Value); return; } String name2, name1, value; // Reads like this: "name2.name1=value". int sep = prName_Value.Pos("="); String names = prName_Value.SubString(1, sep - 1); value = prName_Value.SubString(sep + 1, prName_Value.Length() - sep + 1); sep = names.Pos("."); if (sep) { // Format is "propname.subprop=val": name1 = names.SubString(sep + 1, names.Length() - sep + 1); name2 = names.SubString(1, sep - 1); // name2 is the subcomp of comp. if (!IsPublishedProp(comp, name2)) // No warning. { /* name2 is not a component of comp, but it might be a component of its own, like CheckBox1 is a sub-component of Form1. */ if ((comp = GetSubComponent(comp, name2)) == NULL) return; else { SetPropValue(comp, name1, value); return; } } if (!IsClass(comp, name2)) return; // Get pointer to subObj: TObject *subObj = (TObject *)GetOrdProp(comp, name2); if (subObj == NULL) return; SetPropValue(subObj, name1, value); } else { // Format is "propname=val": SetPropValue(comp, names, value); } }