在Delphi 2009之前我们有以下代码:
function MemoryStreamToString(M : TMemoryStream): String;
var
NewCapacity: Longint;
begin
if (M.Size = > 0) or (M.Memory = nil) then
Result:= ''
else
begin
if TMemoryStreamProtected(M).Capacity = M.Size then
begin
NewCapacity:= M.Size+1;
TMemoryStreamProtected(M).Realloc(NewCapacity);
end;
NullString(M.Memory^)[M.Size]:= #0;
Result:= StrPas(M.Memory);
end;
end;
Run Code Online (Sandbox Code Playgroud)
我们如何使用Delphi 2009将此代码转换为支持Unicode?
我想使用扩展BackupAgentHelper的MyBackUpAgent类在Android中备份数据.我正在使用SharedPreferences来存储数据.
我的主要活动代码是:
public class MainActivity extends Activity {
EditText inputtext;
TextView outputtext;
Button submit;
public static SharedPreferences sharedprefs;
static final String File_Name_Of_Prefrences ="godplay_preferences";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
init();
sharedprefs=getSharedPreferences(File_Name_Of_Prefrences,MODE_PRIVATE);
System.out.println("value="+sharedprefs.getString("Input",""));
outputtext.setText(sharedprefs.getString("Input",""));
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
populateUI();
}
});
}
public void populateUI()
{
String savedinput=inputtext.getText().toString();
System.out.println("savedinput="+savedinput);
outputtext.setText(savedinput);
sharedprefs=getSharedPreferences(File_Name_Of_Prefrences,MODE_PRIVATE);
Editor editor=sharedprefs.edit();
editor.putString("Input",inputtext.getText().toString());
editor.commit();
requestBackup();
}
private void init() throws ClassCastException
{
inputtext=(EditText) findViewById(R.id.edtInputText);
outputtext=(TextView) findViewById(R.id.txtOutputText);
submit=(Button) findViewById(R.id.btnSubmit); …Run Code Online (Sandbox Code Playgroud) 让我们想象一下,我们有以下接口声明.
<?php
namespace App\Sample;
interface A
{
public function doSomething();
}
Run Code Online (Sandbox Code Playgroud)
和B实现接口的类A.
<?php
namespace App\Sample;
class B implements A
{
public function doSomething()
{
//do something
}
public function doBOnlyThing()
{
//do thing that specific to B
}
}
Run Code Online (Sandbox Code Playgroud)
类C将取决于接口A.
<?php
namespace App\Sample;
class C
{
private $a;
public function __construct(A $a)
{
$this->a = $a;
}
public function doManyThing()
{
//this call is OK
$this->a->doSomething();
//if $this->a is instance of B, …Run Code Online (Sandbox Code Playgroud) 例如,我有2个表:sites1和sites2
我需要检查url来自我的html表单的字段是否唯一.
这是我的验证规则:
public function rules()
{
return [
'url' => unique:sites1|unique:sites2'
];
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,此规则仅适用于sites2表格.有没有可能的方法来验证两个表?
php ×2
android ×1
backup ×1
delphi ×1
delphi-2009 ×1
interface ×1
laravel-5 ×1
memorystream ×1
string ×1
type-hinting ×1
unicode ×1
validation ×1